class TableUI extends eui.Component {
    constructor() {
        super();
        this.skinName = "TableUISkin";
    }
    //调整边界
    private moveX: number = -400;
    private moveY: number = 200;
    /**桌子长度 */
    private TableL: number = 1090;
    /**桌子宽度 */
    private TableB: number = 600;
    //桌子梯形的变量
    private trapezoid_H: number = 25;
    private trapezoid_Long: number = 25;
    private trapezoid_Middle: number = 10;

    private ballArr: NewBall[] = [];
    private bounce: number = -0.7;
    private tableBG: eui.Image;
    private tableX: number = 0;
    private tableY: number = 0;
    private tableW: number = 0;
    private tableH: number = 0;
    /**白球 */
    private curBall: NewBall = null;
    private ganImg: eui.Image;
    private ganImg0: eui.Image;
    private ganImg1: eui.Image;
    private ganLen: number = 581;
    private angleSpeed: number = 0;
    private angleNum: number = 0;
    private otherX: number = 0;
    private otherY: number = 0;
    private posArr: any[] = [];
    private tableEageLines:Line[] = [];
    private holeEageLines:Line[] = [];
    private holeR: number = 28;
    private centerX: number = 0;
    private centerY: number = 0;
    //------------------------------16个球
    private ball1: eui.Image;
    private ball2: eui.Image;
    private ball3: eui.Image;
    private ball4: eui.Image;
    private ball5: eui.Image;
    private ball6: eui.Image;
    private ball7: eui.Image;
    private ball8: eui.Image;
    private ball9: eui.Image;
    private ball10: eui.Image;
    private ball11: eui.Image;
    private ball12: eui.Image;
    private ball13: eui.Image;
    private ball14: eui.Image;
    private ball15: eui.Image;
    private ball16: eui.Image;
    /**球管理 */
    private ballImgArr: eui.Image[] = [];
    private chatGroup: eui.Group;
    private chatLabel: eui.Label;
    private chatText: eui.EditableText;
    private sendChat: eui.Image;
    private downIcon: eui.Image;
    private downStart: number = 744;
    private downOver: number = 820;
    private smallGroup: eui.Group;
    private bigGroup: eui.Group;
    private leftGroupPos: any;
    private rightGroupPos: any;
    private leftLabel: eui.Label;
    private rightLabel: eui.Label;
    private leftTurn: eui.Image;
    private rightTurn: eui.Image;
    private tipsBtn1: eui.Image;
    private tipsBtn2: eui.Image;
    private lianjiDragon: dragonBones.Armature;
    private ksDragon: dragonBones.Armature;
    private leftNumImg: eui.Image;
    private rightNumImg: eui.Image;
    /**半径 */
    private _r: number = 0;
    private removeBallArr: number[] = [];
    private firstCollision: number = 0;
    private curVx: number = 0;
    private curVy: number = 0;
    /**第一条瞄准线 */
    private shp1: egret.Shape;
    private shp2: egret.Shape;
    private shp3: egret.Shape;
    private shp4: egret.Shape;
    private shp5: egret.Shape;
    /**蓄力完毕 */
    private isBegin: boolean = false;
    /**球是否在移动 */
    public isMove: boolean = false;
    /**球杆滑动角度 */
    private huadongAngle: number = 0;
    /**力度 */
    private long: number = 0;
    private moveTime: number = 0;
    /**白球图片 */
    private whiteBall: eui.Image = null;
    /**摆球禁止图片 */
    private xIcon: eui.Image = null;
    /**排行榜 */
    private tipsUI: TipsUI = new TipsUI();
    /**0不摆球，1摆球，2自由球 */
    private isBaiqiu: number = 0;
    /**是否是自己的回合 */
    private isOwnGame: boolean = false;
    private curActionNum: number = 0;
    private myChairId: number = -1;
    private otherChairId: number = -1;
    /**0 选择界面 1联机对战 2练习游戏 */
    private isLianxi: number = 0;
    public myBrowser: string = "";
    private myColor: number = -1;
    private lightArr: dragonBones.Armature[] = [];
    private countdownTimer: egret.Timer;
    private curTimerNum: number = 0;
    private isLoading: number = 0;//0,空挡，1，是读条，2，是运行
    private lidu: eui.Image;
    private lidudi: eui.Image;
    private liduLabel: eui.Label;
    private isKsBtn: boolean = false;
    private lianxiImg: eui.Image;
    private startbg: eui.Image; //游戏开始背景
    private end: eui.Image;     //游戏结束背景
    private goplay: eui.Image;  //开始游戏按钮
    private close: eui.Image;   //结束界面关闭按钮
    private photo: eui.Image;   //玩家头像
    private playername: eui.Label;   //玩家名字
    private score: eui.Label;   //玩家得分文本
    private Maxscore: eui.Label;//玩家最高分文本
    private goal: number = 100;    //玩家得分
    private maxgoal: number = 666; //玩家最高分
    private retry: eui.Image;  //重试
    private share: eui.Image;  //分享
    private offs: any[] = [];  //解散界面组件
    /**进球数*/
    private iii: number = 0;

    //TableUISkin.exml
    private back: eui.Image;//退出游戏返回主菜单
    private Menu: eui.Image;//菜单(设置音量)
    private Tips: eui.Image;//玩法
    private multiple: eui.Label;//倍数
    private timer: eui.Label;//计时器
    private scores: eui.Label;//即时分数
    private multipletext: eui.Label;//即时倍数
    private timetext: eui.Label;//计时器显示
    private soloTime: number = 60;//单人模式时间(秒)
    private soloTimer: egret.Timer = new egret.Timer(1000, 0);//单人模式计时器
    private stop: boolean = false;
    private scoretext: eui.Label;//得分显示 注：TEXT 显示要实时更新
    /**累计得分 */
    private scoreiii: number = 0;



    //声音变量
    private soundganqiu: egret.Sound;
    private soundrudong: egret.Sound;
    private soundzhuangbian: egret.Sound;
    private soundzhuangqiu: egret.Sound;



    //-----------------------------------------------------------------------
    /**本地服务器 */
    private homeServer = FakeServerManage.getInstance();
    /**打球先后顺序
     * 0-我方
     * 1-敌方
     */
    private order: number = 0;
    /**错误消息弹窗 */
    private errorMsgMain: ErrorMessage = new ErrorMessage();
    /**匹配计时器 */
    private matchTimer: egret.Timer;
    /**匹配超时数 */
    private matchTimeOutNum: number = GameData.matchWaitTime;

    protected createChildren(): void {
        super.createChildren();
        this.InitPannels();
        this.updateTime();
        //this.StartBg();
        //this.EndBg();
        this.multipletext.text = "1倍";

        this.tableX = this.tableBG.x + this.moveX;
        this.tableY = this.tableBG.y + this.moveY;
        this.tableW = this.tableBG.width;
        this.tableH = this.tableBG.height;

        this.smallGroup.visible = false;
        this.bigGroup.visible = false;
        this.leftGroupPos = { x: this.smallGroup.x, y: this.smallGroup.y };
        this.rightGroupPos = { x: this.bigGroup.x, y: this.bigGroup.y };

        this.leftLabel.visible = false;
        this.rightLabel.visible = false;

        this.leftTurn.visible = false;
        this.rightTurn.visible = false;

        this.ballImgArr = [this.ball1, this.ball2, this.ball3, this.ball4, this.ball5, this.ball6, this.ball7, null, this.ball9, this.ball10, this.ball11, this.ball12, this.ball13, this.ball14, this.ball15];
        this.ball8.alpha = 0.4;
        this.ball16.alpha = 0.4;
        for (var i: number = 0; i < this.ballImgArr.length; i++) {
            if (this.ballImgArr[i]) {
                this.ballImgArr[i].alpha = 0.4;
            }
        }
        /**
         * 
         * 横板桌球球洞信息坐标
         * 
         */
        // this.posArr = [//tableX背景图片（tableBG）长 tableY背景图片宽
        //     {//[0] （上左） 
        //         //0号洞 右边墙起点
        //         x1: this.tableX + 204,
        //         y1: this.tableY + 80,
        //         //0号洞 下边墙起点
        //         x2: this.tableX + 166,
        //         y2: this.tableY + 120,
        //         //0号洞中心坐标（posArr[0].hx,posArr[0].hy）
        //         hx: this.tableX + 172,
        //         hy: this.tableY + 89,
        //     },
        //     {//[1] （上中）1号洞
        //         //1号洞 
        //         x1: this.tableX + 683,
        //         y1: this.tableY + 80,
        //         //
        //         x2: this.tableX + 746,
        //         y2: this.tableY + 80,
        //         //
        //         hx: this.tableX + 715,
        //         hy: this.tableY + 70,
        //     },
        //     {//[2] （上右）2号洞
        //         x1: this.tableX + 1226,
        //         y1: this.tableY + 80,
        //         x2: this.tableX + 1264,
        //         y2: this.tableY + 120,
        //         hx: this.tableX + 1257,
        //         hy: this.tableY + 89,
        //     },
        //     {//[3] （下左）3号洞
        //         x1: this.tableX + 166,
        //         y1: this.tableY + 596,
        //         x2: this.tableX + 204,
        //         y2: this.tableY + 636,
        //         hx: this.tableX + 172,
        //         hy: this.tableY + 628,
        //     },
        //     {//[4] （下中）4号洞
        //         x1: this.tableX + 683,
        //         y1: this.tableY + 636,
        //         x2: this.tableX + 746,
        //         y2: this.tableY + 636,
        //         hx: this.tableX + 715,
        //         hy: this.tableY + 647,
        //     },
        //     {//[5] （下右）5号洞
        //         x1: this.tableX + 1264,
        //         y1: this.tableY + 596,
        //         x2: this.tableX + 1226,
        //         y2: this.tableY + 636,
        //         hx: this.tableX + 1257,
        //         hy: this.tableY + 628,
        //     }
        // ];


        /**
         * 竖版桌球球洞信息坐标
         */
        this.posArr = [//tableX背景图片（tableBG）长 tableY背景图片宽
            {//[0] （上左） 
                //0号洞 右边墙起点
                x1: this.tableX + 437,
                y1: this.tableY + 870,
                //0号洞 下边墙起点
                x2: this.tableX + 477,
                y2: this.tableY + 907,
                //0号洞中心坐标（posArr[0].hx,posArr[0].hy）
                hx: this.tableX + 445.5,
                hy: this.tableY + 901.5,
            },
            {//[1] （上中）1号洞
                //1号洞 
                x1: this.tableX + 437,
                y1: this.tableY + 390,
                //
                x2: this.tableX + 437,
                y2: this.tableY + 327,
                //
                hx: this.tableX + 427,
                hy: this.tableY + 359,
            },
            {//[2] （上右）2号洞
                x1: this.tableX + 437,
                y1: this.tableY + (-152),
                x2: this.tableX + 477,
                y2: this.tableY + (-191),
                hx: this.tableX + 445.5,
                hy: this.tableY + (-183.5),
            },
            {//[3] （下左）3号洞
                x1: this.tableX + 953,
                y1: this.tableY + 907,
                x2: this.tableX + 993,
                y2: this.tableY + 870,
                hx: this.tableX + 984.5,
                hy: this.tableY + 901.5,
            },
            {//[4] （下中）4号洞
                x1: this.tableX + 993,
                y1: this.tableY + 390,
                x2: this.tableX + 993,
                y2: this.tableY + 327,
                hx: this.tableX + 1003,
                hy: this.tableY + 359,
            },
            {//[5] （下右）5号洞
                x1: this.tableX + 953,
                y1: this.tableY + (-191),
                x2: this.tableX + 993,
                y2: this.tableY + (-152),
                hx: this.tableX + 984.5,
                hy: this.tableY + (-183.5),
            }
        ];

        var rect: egret.Rectangle = new egret.Rectangle(0, 0, this.chatGroup.width, this.chatGroup.height);
        this.chatGroup.mask = rect;

        this.centerX = this.posArr[0].hx + (this.posArr[3].hx - this.posArr[0].hx) * 0.5;
        this.centerY = this.posArr[0].hy + (this.posArr[2].hy - this.posArr[0].hy) / 2;

        //for(var i:number=0;i<this.posArr.length;i++)
        //{
        //    var shp:egret.Shape = new egret.Shape();
        //    shp.graphics.lineStyle( 1, 0x00ff00 );
        //    shp.graphics.drawCircle(this.posArr[i].x1,this.posArr[i].y1,1);
        //    shp.graphics.endFill();
        //    this.addChild(shp);
        //
        //    var shp1:egret.Shape = new egret.Shape();
        //    shp1.graphics.lineStyle( 1, 0x00ff00 );
        //    shp1.graphics.drawCircle(this.posArr[i].x2,this.posArr[i].y2,1);
        //    shp1.graphics.endFill();
        //    this.addChild(shp1);
        //
        //    var shp2:egret.Shape = new egret.Shape();
        //    shp2.graphics.lineStyle( 1, 0x00ff00 );
        //    shp2.graphics.drawCircle(this.posArr[i].hx,this.posArr[i].hy,this.holeR);
        //    shp2.graphics.endFill();
        //    this.addChild(shp2);
        //}

        this.ganImg = new eui.Image("gan");
        this.ganImg.anchorOffsetX = 12;
        this.ganImg.anchorOffsetY = 5;
        this.ganImg.visible = false;
        this.addChild(this.ganImg);

        this.lianxiImg = new eui.Image("lianxiBtn1");
        this.lianxiImg.anchorOffsetX = 48;
        this.lianxiImg.x = this.centerX;
        this.lianxiImg.y = this.centerY + 80;
        this.addChild(this.lianxiImg);
        this.lianxiImg.name = "lianxi";
        //this.lianxiImg.visible = false; //隐藏最初开始

        var dragonbonesData = RES.getRes("ks3");
        var textureData = RES.getRes("ks2");
        var texture = RES.getRes("ks1");
        var dragonbonesFactory: dragonBones.EgretFactory = new dragonBones.EgretFactory();
        dragonbonesFactory.addDragonBonesData(dragonBones.DataParser.parseDragonBonesData(dragonbonesData));
        dragonbonesFactory.addTextureAtlas(new dragonBones.EgretTextureAtlas(texture, textureData));
        this.ksDragon = dragonbonesFactory.buildArmature("armatureName");
        this.ksDragon.display.name = "ks";
        this.addChild(this.ksDragon.display);
        //this.ksDragon.display.visible = false; //隐藏最初开始

        this.isKsPlay = true;
        this.ksDragon.display.x = this.centerX;
        this.ksDragon.display.y = this.centerY;
        dragonBones.WorldClock.clock.add(this.ksDragon);
        //开始游戏侦听
        this.ksDragon.addEventListener(egret.Event.COMPLETE, function () {
            //dragonBones.WorldClock.clock.remove(_this.ksDragon);
            this.isKsBtn = true;
            this.isKsPlay = false;
            this.ksDragon.display.touchEnabled = true;
            this.ksDragon.display.addEventListener(egret.TouchEvent.TOUCH_TAP, this.startConnect, this);

            this.lianxiImg.addEventListener(egret.TouchEvent.TOUCH_TAP, this.lianxiFunc, this);

            console.log("11111");
        }.bind(this), this);
        this.ksDragon.animation.gotoAndPlay("zq_ks_01a", -1, -1, 1);


        var dragonbonesData1 = RES.getRes("lianji3");
        var textureData1 = RES.getRes("lianji2");
        var texture1 = RES.getRes("lianji1");
        var dragonbonesFactory1: dragonBones.EgretFactory = new dragonBones.EgretFactory();
        dragonbonesFactory1.addDragonBonesData(dragonBones.DataParser.parseDragonBonesData(dragonbonesData1));
        dragonbonesFactory1.addTextureAtlas(new dragonBones.EgretTextureAtlas(texture1, textureData1));
        this.lianjiDragon = dragonbonesFactory1.buildArmature("armatureName");
        this.lianjiDragon.display.x = this.centerX + 430;
        this.lianjiDragon.display.y = this.centerY;

        egret.Ticker.getInstance().register(
            function (frameTime: number) {
                dragonBones.WorldClock.clock.advanceTime(frameTime / 1000);
                return true;
            },
            this
        );

        document.addEventListener("mousemove", this.mouseMoveGan);

        this.setTimeNum(0);

        this.myBrowser = getBrowserType();

        this.shp1 = new egret.Shape();
        this.addChild(this.shp1);
        this.shp1.alpha = 0.6;

        this.shp2 = new egret.Shape();
        this.addChild(this.shp2);
        this.shp2.alpha = 0.6;

        this.shp3 = new egret.Shape();
        this.addChild(this.shp3);
        this.shp3.alpha = 0.6;

        this.shp4 = new egret.Shape();
        this.addChild(this.shp4);
        this.shp4.alpha = 0.6;
        this.shp5 = new egret.Shape();
        this.addChild(this.shp5);
        this.shp5.alpha = 0.6;

        this.long = 251 * 0.7;
        this.liduLabel.text = "" + 70 + "/100";
        var rect: egret.Rectangle = new egret.Rectangle(251 - this.long, 0, this.long, 42);
        this.lidu.mask = rect;
        this.lidu.touchEnabled = false;
        /**提示文字 */
        this.promptWord = new PromptWord();
        this.promptWord.anchorOffsetX = 138;
        this.promptWord.x = this.centerX;
        this.promptWord.y = this.centerY - 230;

        this.soundganqiu = RES.getRes("ganqiu");
        this.soundrudong = RES.getRes("rudong");
        this.soundzhuangbian = RES.getRes("zhuangbian");
        this.soundzhuangqiu = RES.getRes("zhuangqiu");




        //this.AdjustposArr();
        //将球案边添加一个梯形
        this.TrapezoidBallSide(this.trapezoid_Long, this.trapezoid_Middle, this.trapezoid_H);
        //画球案
        this.debugDrawTable();

        this.homeServer.gameSence = this;
        webNetworkMananger.getInstance().gameSceneRec = this;
    }

    //玩法按钮初始化
    protected InitPannels(): void {
        this.Tips.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
            let w = new WanFa();
            w.x = screenSize.width / 7;
            w.y = screenSize.height / 3;
            this.stage.addChild(w);
            w.SetHowToPlay("桌球的一共包含16颗彩球和一颗白球 \n 玩家需在一分钟内尽可能的打进更多的球");
        }, this);


        this.Menu.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
            let w = new SettingsPannel();
            w.x = screenSize.width / 7;
            w.y = screenSize.height / 3;
            this.stage.addChild(w);
        }, this);

    }

    private SMColor(msg) {
        var num: number = 0;
        if (this.myChairId == 0) {
            num = msg.chair0Color;
        }
        else if (this.myChairId == 1) {
            num = msg.chair1Color;
        }
        this.myColor = num;
        if (num == 0) {
            this.smallGroup.x = this.leftGroupPos.x;
            this.smallGroup.y = this.leftGroupPos.y;
            this.smallGroup.visible = true;

            this.bigGroup.x = this.rightGroupPos.x;
            this.bigGroup.y = this.rightGroupPos.y;
            this.bigGroup.visible = true;
        }
        else if (num == 1) {
            this.smallGroup.x = this.rightGroupPos.x;
            this.smallGroup.y = this.rightGroupPos.y;
            this.smallGroup.visible = true;

            this.bigGroup.x = this.leftGroupPos.x;
            this.bigGroup.y = this.leftGroupPos.y;
            this.bigGroup.visible = true;
        }

        if (this.leftLabel.parent) {
            this.removeChild(this.leftLabel);
        }
        if (this.rightLabel.parent) {
            this.removeChild(this.rightLabel);
        }
    }

    private SMChat(msg) {
        this.chatLabel.text = this.chatLabel.text + "\n" + msg.info;
        this.chatLabel.bottom = 0;
    }
    private sendFunc() {
        if (this.isLianxi == 1) {
            var str: string = "" + GameData.myAccount + ": " + this.chatText.text;

        }
        this.chatText.text = "";
    }

    private downFunc(e: egret.TouchEvent) {
        if (e.stageY < this.downStart) {
            this.downIcon.y = this.downStart;
            return;
        }
        if (e.stageY > this.downOver) {
            this.downIcon.y = this.downOver;
            return;
        }
        this.downIcon.y = e.stageY;
        this.chatLabel.bottom = -(this.downIcon.y - this.downOver);
    }

    /**练习模式 */
    private lianxiFunc() {
        //this.startbg.visible = false; // 隐藏开始界面
        var _spr2: egret.DisplayObject = this.getChildByName("ks");
        _spr2.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.startConnect, this);
        if (_spr2.parent) {
            this.removeChild(_spr2);
        }
        this.isKsBtn = false;

        var _spr3: egret.DisplayObject = this.getChildByName("lianxi");
        _spr3.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.lianxiFunc, this);
        if (_spr3.parent) {
            this.removeChild(_spr3);
        }
        this.isLianxi = 2;
        this.isOwnGame = true;
        this.ganImg0.visible = false;
        this.ganImg1.visible = true;
        this.isBaiqiu = 1;

        egret.setTimeout(this.startGame1, this, 100);
    }
    /**等待匹配 */
    public waitingMatch() {
        this.matchTimer = new egret.Timer(1000, 0);
        this.matchTimer.addEventListener(egret.TimerEvent.TIMER, this.waitMsgShow, this);
        this.matchTimer.addEventListener(egret.TimerEvent.TIMER_COMPLETE, this.matchTimeout, this);

    }
    /**等待信息显示 */
    public waitMsgShow() {
        this.matchTimeOutNum--;
        var dengdai: eui.Label = new eui.Label();
        dengdai.text = "正在匹配..." + this.matchTimeOutNum + "s";
        dengdai.width = this.stage.stageWidth;
        dengdai.y = this.stage.stageHeight / 2;
        dengdai.name = "dengdai";
        dengdai.textAlign = egret.HorizontalAlign.CENTER;
        this.addChild(dengdai);
    }
    /**匹配超时处理 */
    public matchTimeout() {
        this.matchTimer.stop();
        this.matchTimer.removeEventListener(egret.TimerEvent.TIMER, this.waitMsgShow, this);
        this.matchTimer.removeEventListener(egret.TimerEvent.TIMER, this.waitMsgShow, this);
        this.matchTimeOutNum = GameData.matchWaitTime;
        //预留处理
    }
    /**匹配成功 */
    public matchSuccessful() {
        this.isLianxi = 2;
        this.isOwnGame = true;
        this.ganImg0.visible = false;
        this.ganImg1.visible = true;
        this.isBaiqiu = 1;
        this.startGame1();
    }

    /**联网模式 */
    private startConnect() {
        this.isLianxi = 1;
        /**开始游按钮*/
        var _spr2: egret.DisplayObject = this.getChildByName("ks");
        /**移除侦听 */
        _spr2.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.startConnect, this);
        /**从容器中清除 */
        if (_spr2.parent) {
            this.removeChild(_spr2);
        }
        //--------------------关闭开关
        this.isKsBtn = false;
        this.isKsPlay = false;
        //--------------------把开始动画从时间轴去除
        dragonBones.WorldClock.clock.remove(this.ksDragon);

        var _spr3: egret.DisplayObject = this.getChildByName("lianxi");
        _spr3.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.lianxiFunc, this);
        if (_spr3.parent) {
            this.removeChild(_spr3);
        }

        var dengdai: eui.Label = new eui.Label();
        dengdai.text = "等待其他玩家...";
        dengdai.width = 1440;
        dengdai.y = this.centerY;
        dengdai.name = "dengdai";
        dengdai.textAlign = egret.HorizontalAlign.CENTER;
        this.addChild(dengdai);

        egret.setTimeout(e => {
            if (GameData.isStandalone) {
                this.matchSuccessful();
            } else {
                webNetworkMananger.getInstance().connect();
            }
        }, this, 1000 / 60);
    }
    public isCanClose: boolean = false;
    private SMLogin(msg) {
        GameData.myAccount = msg.playerState.account;
    }
    /**联网摆球 */
    private SMPutBall(msg) {
        if (this.isBaiqiu == 1) {
            this.countdownFunc(true, 15);
        }
        else {
            this.countdownFunc(true, 25);
        }
        this.isBaiqiu = 0;
        this.curBall.isJindong = -1;
        this.curBall.lastX = this.curBall.nextX = Number(msg.ball.x);
        this.curBall.lastY = this.curBall.nextY = Number(msg.ball.y);
        setBaiPos(msg.ball.x, msg.ball.y);
        refreshUI();
    }

    private idTO1: number;
    /**联网游戏结束 */
    private SMGameEnd(msg) {
        if (this.isLosePrompt) {
            this.idTO1 = egret.setTimeout(this.SMGameEnd1, this, 3000, msg);
        } else {
            this.SMGameEnd1(msg);
        }
    }
    private SMGameEnd1(msg) {
        if (this.isLosePrompt) {
            egret.clearTimeout(this.idTO1);
            this.isLosePrompt = false;
        }
        this.countdownFunc(false);
        if (msg.code == 1) {
            return;
        }
        this.isOwnGame = false;
        this.isBaiqiu = 0;
        this.ganImg.visible = false;
        this.shp1.graphics.clear();
        this.shp2.graphics.clear();
        this.shp3.graphics.clear();
        if (msg.winChair == this.myChairId) {
            var winUI: WinUI = new WinUI();
            winUI.x = this.centerX - 546 / 2;
            winUI.y = this.centerY - 469 / 2;

            this.addChild(winUI);
            winUI.playAction();
        }
        else {
            var loseUI: LoseUI = new LoseUI();
            loseUI.x = this.centerX - 546 / 2;
            loseUI.y = this.centerY - 469 / 2;

            this.addChild(loseUI);
            loseUI.playAction();
        }

    }
    /**对方杆的位置 */
    private SMCue(msg) {
        this.ganImg.visible = true;
        this.ganImg.rotation = Number(msg.angle);
        this.ganImg.x = Number(msg.point.x);
        this.ganImg.y = Number(msg.point.y);
    }

    private SMHitPoint(msg) {

    }

    private SMHitAngle(msg) {

    }
    /*
     * word1    对方黑球进袋 判负
     * word2    黑球进袋 判负
     * word3    击球超时
     * word4    击球犯规 对方自由球
     * word5    击球犯规 你获得自由球
     * word6    交换球权
     * word7    母球落袋 对方自由球
     * word8    母球落袋 你获得自由球
     * word9    请击球
     * word10   请重新开球
     * word11   选定颜色
     * word12   母球落袋 判负
     * 
     */
    private isLosePrompt: boolean = false;
    private SMTableState(msg) {
        var blacknum: number = -1;
        if (msg.code == 5) {
            blacknum = msg.msg.charAt(msg.msg.length - 1);
        }
        if (msg.code == 6) {
            if (msg.msg.indexOf('word1 or word2') != -1) {
                blacknum = msg.msg.charAt(msg.msg.length - 1);
            }
        }
        if (blacknum != -1) {
            if (blacknum == this.myChairId) {
                if (this.myColor == 0) {
                    this.ball8.alpha = 1;
                }
                else if (this.myColor == 1) {
                    this.ball16.alpha = 1;
                }
            }
            else {
                if (this.myColor == 1) {
                    this.ball8.alpha = 1;
                }
                else if (this.myColor == 0) {
                    this.ball16.alpha = 1;
                }
            }
        }
        if (msg.code == 3) {
            this.isBaiqiu = 2;
            this.countdownFunc(true, 15);
            this.ganImg.visible = false;
        }
        if (msg.code == 2 || msg.code == 4) {
            this.countdownFunc(true, 25);
        }
        var wordx = '';
        if (this.isTOHit) {
            wordx = 'word3';
            this.isTOHit = false;
        }
        else {
            if (msg.msg.indexOf('word1 or word2') != -1) {
                this.isLosePrompt = true;
                var curChairId = msg.msg.charAt(msg.msg.length - 1);
                if (this.myChairId == curChairId) {
                    wordx = 'word2';
                }
                else {
                    wordx = 'word1';
                }
            }
            else if (msg.msg == 'word4 or word5') {
                if (msg.nextChair == this.myChairId) {
                    wordx = 'word5';
                } else {
                    wordx = 'word4';
                }
            }
            else if (msg.msg == 'word6' || msg.msg == 'word11') {
                wordx = msg.msg;
            }
            else if (msg.msg == 'word7 or word8') {
                if (msg.nextChair == this.myChairId) {
                    wordx = 'word8';
                }
                else {
                    wordx = 'word7';
                }
            }
            else if ((msg.msg == 'word9' || msg.msg == 'word10') && msg.nextChair == this.myChairId) {
                wordx = msg.msg;
            }
            else if (msg.msg.indexOf('word12') != -1) {

                var curChairId = msg.msg.charAt(msg.msg.length - 1);
                if (this.myChairId == curChairId) {
                    this.isLosePrompt = true;
                    wordx = 'word12';
                }
            }
        }
        if (wordx != '') {
            this.promptWord.setSour(wordx);
            if (!this.promptWord.parent) {
                this.addChild(this.promptWord);
            }
        }

        this.curActionNum = msg.nextChair;
        if (msg.nextChair == this.myChairId) {
            this.isOwnGame = true;
            this.ganImg0.visible = false;
            this.ganImg1.visible = true;

            this.leftTurn.visible = true;
            this.rightTurn.visible = false;

            if (this.myColor == 0) {
                for (var i: number = 0; i < this.ballArr.length; i++) {
                    var ball: NewBall = this.ballArr[i];
                    if (ball.idx >= 1 && ball.idx <= 7) {
                        var dragonbonesData = RES.getRes("light3");
                        var textureData = RES.getRes("light2");
                        var texture = RES.getRes("light1");
                        var dragonbonesFactory: dragonBones.EgretFactory = new dragonBones.EgretFactory();
                        dragonbonesFactory.addDragonBonesData(dragonBones.DataParser.parseDragonBonesData(dragonbonesData));
                        dragonbonesFactory.addTextureAtlas(new dragonBones.EgretTextureAtlas(texture, textureData));
                        var armature: dragonBones.Armature = dragonbonesFactory.buildArmature("armatureName");
                        this.addChild(armature.display);
                        armature.display.x = ball.nextX;
                        armature.display.y = ball.nextY;
                        dragonBones.WorldClock.clock.add(armature);
                        armature.animation.gotoAndPlay("zq_guang_001a", -1, -1, 0);
                        this.lightArr.push(armature);
                    }
                }
            }
            else if (this.myColor == 1) {
                for (var i: number = 0; i < this.ballArr.length; i++) {
                    var ball: NewBall = this.ballArr[i];
                    if (ball.idx >= 9 && ball.idx <= 15) {
                        var dragonbonesData = RES.getRes("light3");
                        var textureData = RES.getRes("light2");
                        var texture = RES.getRes("light1");
                        var dragonbonesFactory: dragonBones.EgretFactory = new dragonBones.EgretFactory();
                        dragonbonesFactory.addDragonBonesData(dragonBones.DataParser.parseDragonBonesData(dragonbonesData));
                        dragonbonesFactory.addTextureAtlas(new dragonBones.EgretTextureAtlas(texture, textureData));
                        var armature: dragonBones.Armature = dragonbonesFactory.buildArmature("armatureName");
                        this.addChild(armature.display);
                        armature.display.x = ball.nextX;
                        armature.display.y = ball.nextY;
                        dragonBones.WorldClock.clock.add(armature);
                        armature.animation.gotoAndPlay("zq_guang_001a", -1, -1, 0);
                        this.lightArr.push(armature);
                    }
                }
            }
        }
        else {
            this.isOwnGame = false;
            this.ganImg0.visible = true;
            this.ganImg1.visible = false;

            this.leftTurn.visible = false;
            this.rightTurn.visible = true;
        }

        if (msg.combo >= 2 && msg.combo <= 7) {
            if (!this.lianjiDragon.display.parent) {
                this.addChild(this.lianjiDragon.display);
            }
            dragonBones.WorldClock.clock.add(this.lianjiDragon);
            this.lianjiDragon.addEventListener(egret.Event.COMPLETE, function () {
                dragonBones.WorldClock.clock.remove(this.lianjiDragon);
                if (this.lianjiDragon.display.parent) {
                    this.removeChild(this.lianjiDragon.display);
                }

            }.bind(this), this);
            this.lianjiDragon.animation.gotoAndPlay("zq_00" + msg.combo + "a", -1, -1, 1);
        }
    }

    public PlayerEnter(msg) {
        if (Number(msg.playerState.account) == GameData.myAccount) {
            this.myChairId = msg.playerState.chair;
        }
        else {
            this.otherChairId = msg.playerState.chair;
        }
    }

    public SMGameStart(msg) {
        this.curActionNum = msg.nextChair;
        if (msg.nextChair == this.myChairId) {
            this.isOwnGame = true;
            this.isBaiqiu = 1;

            this.ganImg0.visible = false;
            this.ganImg1.visible = true;

            this.leftTurn.visible = true;
            this.rightTurn.visible = false;
        }
        else {
            this.isOwnGame = false;
            this.isBaiqiu = 1;

            this.ganImg0.visible = true;
            this.ganImg1.visible = false;

            this.leftTurn.visible = false;
            this.rightTurn.visible = true;
        }

        this.leftLabel.visible = true;
        this.rightLabel.visible = true;

        this.startGame1();
    }
    /**摆球 */
    public startGame1() {
        this.curBall = new NewBall(0);
        this.curBall.lastX = this.posArr[0].hx + (this.posArr[2].hx - this.posArr[0].hx) * 0.1;
        this.curBall.lastY = this.posArr[0].hy + (this.posArr[3].hy - this.posArr[0].hy) / 2;
        this.curBall.nextX = this.curBall.lastX;
        this.curBall.nextY = this.curBall.lastY;
        this.curBall.name = "cur";
        this.ballArr.push(this.curBall);

        // this.otherX = this.posArr[0].hx + (this.posArr[2].hx - this.posArr[0].hx) * 0.7;
        // this.otherY = this.posArr[0].hy + (this.posArr[3].hy - this.posArr[0].hy) / 2;
        this.otherX = this.posArr[0].hx + (this.posArr[3].hx - this.posArr[0].hx) / 2;
        this.otherY = this.posArr[0].hy + (this.posArr[2].hy - this.posArr[0].hy) * 0.7;

        for (var i: number = 0; i < 5; i++) {
            var ball: NewBall = new NewBall(this.ballArr.length);
            ball.lastY = this.otherY - (2 * ball.radius + 1) * i * Math.cos(Math.PI / 6);
            ball.lastX = this.otherX - (2 * ball.radius + 1) * i * Math.sin(Math.PI / 6);
            ball.nextX = ball.lastX;
            ball.nextY = ball.lastY;
            this.ballArr.push(ball);
            for (var j: number = 1; j <= i; j++) {
                var ball1: NewBall = new NewBall(this.ballArr.length);
                ball1.lastY = ball.lastY;
                ball1.lastX = ball.lastX + 2 * ball1.radius * j + j;
                ball1.nextX = ball1.lastX;
                ball1.nextY = ball1.lastY;
                this.ballArr.push(ball1);
            }
        }

        for (var i: number = 0; i < this.ballArr.length; i++) {
            var ball: NewBall = this.ballArr[i];
            setBallPos1(ball.nextX, ball.nextY, i);
        }

        refreshUI();

        egret.setTimeout(this.startGame2, this, 1000 / 60);
    }
    /**时间更新 */
    protected updateTime() {
        if (!this.stop) {
            //开始计时器功能
            this.timetext.text = parseInt((this.soloTime / 60).toString()) + "分" + this.soloTime % 60 + "秒";
            this.soloTimer.addEventListener(egret.TimerEvent.TIMER, () => {
                this.soloTime--;
                this.timetext.text = parseInt((this.soloTime / 60).toString()) + "分" + this.soloTime % 60 + "秒";
                if (this.soloTime <= 0) {
                    this.soloTime = 0;
                    this.timetext.text = parseInt((this.soloTime / 60).toString()) + "分" + this.soloTime % 60 + "秒";

                    this.soloTimer.stop();
                }
            }, this);
            this.soloTimer.start();
        }
    }

    private startGame2() {
        this._r = this.ballArr[0].radius;
        //--------------------------------------------------------倒计时
        this.countdownTimer = new egret.Timer(1000, 0);
        this.countdownTimer.addEventListener(egret.TimerEvent.TIMER, this.startCountDown, this);

        this.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.beginFunc, this);
        this.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.moveFunc, this);
        this.addEventListener(egret.TouchEvent.TOUCH_END, this.endFunc, this);

        this.tipsBtn1.addEventListener(egret.TouchEvent.TOUCH_TAP, this.showTips, this);
        this.tipsBtn2.addEventListener(egret.TouchEvent.TOUCH_TAP, this.showTips, this);
        /**力度 */
        this.lidudi.addEventListener(egret.TouchEvent.TOUCH_TAP, this.liduFunc, this);
        /**聊天，发送消息 */
        this.sendChat.addEventListener(egret.TouchEvent.TOUCH_TAP, this.sendFunc, this);
        this.chatText.text = "";

        this.isCanMove = true;

        if (this.isLianxi == 1) {
            this.downIcon.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.downFunc, this);
        }

        this.ganImg.visible = false;

        var _spr1: egret.DisplayObject = this.getChildByName("dengdai");
        if (_spr1 != null &&_spr1.parent) {
            this.removeChild(_spr1);
        }

        if (this.isLianxi == 1) {
            this.countdownFunc(true, 15);
        }

    }
    /**是否可以移动鼠标 */
    private isCanMove: boolean = false;
    private removeAllEventListener() {
        this.removeEventListener(egret.Event.ENTER_FRAME, this.enterFrame, this);

        this.removeEventListener(egret.TouchEvent.TOUCH_BEGIN, this.beginFunc, this);
        this.removeEventListener(egret.TouchEvent.TOUCH_MOVE, this.moveFunc, this);
        this.removeEventListener(egret.TouchEvent.TOUCH_END, this.endFunc, this);

        this.tipsBtn1.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.showTips, this);
        this.tipsBtn2.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.showTips, this);
        this.lidudi.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.liduFunc, this);

        this.sendChat.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.sendFunc, this);

        this.countdownTimer.removeEventListener(egret.TimerEvent.TIMER, this.startCountDown, this);

        this.isCanMove = false;

        if (this.isLianxi == 1) {
            this.downIcon.removeEventListener(egret.TouchEvent.TOUCH_MOVE, this.downFunc, this);
        }
    }

    public quitFunc() {

        this.resetUI();

        if (this.isLianxi == 1) {
            this.isCanClose = true;
        }

        this.isLianxi = 0;

        this.lianxiImg = new eui.Image("lianxiBtn1");
        this.lianxiImg.anchorOffsetX = 48;
        this.lianxiImg.x = this.centerX;
        this.lianxiImg.y = this.centerY;
        this.addChild(this.lianxiImg);
        this.lianxiImg.name = "lianxi";

        var dragonbonesData = RES.getRes("ks3");
        var textureData = RES.getRes("ks2");
        var texture = RES.getRes("ks1");
        var dragonbonesFactory: dragonBones.EgretFactory = new dragonBones.EgretFactory();
        dragonbonesFactory.addDragonBonesData(dragonBones.DataParser.parseDragonBonesData(dragonbonesData));
        dragonbonesFactory.addTextureAtlas(new dragonBones.EgretTextureAtlas(texture, textureData));
        this.ksDragon = dragonbonesFactory.buildArmature("armatureName");
        this.ksDragon.display.name = "ks";
        this.addChild(this.ksDragon.display);
        this.isKsPlay = true;
        this.ksDragon.display.x = this.centerX;
        this.ksDragon.display.y = this.centerY + 80;
        dragonBones.WorldClock.clock.add(this.ksDragon);

        this.ksDragon.addEventListener(egret.Event.COMPLETE, function () {
            //dragonBones.WorldClock.clock.remove(_this.ksDragon);
            this.isKsBtn = true;
            this.isKsPlay = false;
            this.ksDragon.display.touchEnabled = true;
            this.ksDragon.display.addEventListener(egret.TouchEvent.TOUCH_TAP, this.startConnect, this);

            this.lianxiImg.addEventListener(egret.TouchEvent.TOUCH_TAP, this.lianxiFunc, this);
        }.bind(this), this);
        this.ksDragon.animation.gotoAndPlay("zq_ks_01a", -1, -1, 1);

        if (this.isLianxi == 1) {
        }

    }
    /**
     * 游戏开始界面
     */
    private StartBg() {
        this.startbg = new eui.Image("start_png");
        this.startbg.width = this.stage.stageWidth / 3;  //480
        this.startbg.height = this.stage.stageHeight;    //900
        this.startbg.x = this.stage.stageWidth / 2 - this.startbg.width / 2;
        this.addChild(this.startbg);
        this.goplay = new eui.Image("kaishi_png");
        this.goplay.width = this.stage.stageWidth / 9;
        this.goplay.height = this.stage.stageHeight / 8;
        this.goplay.x = 750;
        this.goplay.y = 750;
        this.addChild(this.goplay);
        this.goplay.visible = false;//暂未用
        this.goplay.addEventListener(egret.TouchEvent.TOUCH_TAP, this.lianxiFunc, this);//开始练习
        this.goplay.addEventListener(egret.TouchEvent.TOUCH_TAP, this.HidstartBg, this);
    }
    /**
     * 隐藏开始界面
     */
    private HidstartBg() {
        this.startbg.visible = false;
        //this.goplay.visible = false;

    }
    /**
    * 游戏结束界面
    */
    private EndBg() {
        this.end = new eui.Image("lose");
        this.end.width = this.stage.stageWidth / 2.5;
        this.end.height = this.stage.stageHeight;
        this.end.x = this.stage.stageWidth / 2 - this.end.width / 2;
        this.addChild(this.end);
        this.close = new eui.Image("off_png");
        this.close.x = 890;
        this.addChild(this.close);
        this.close.addEventListener(egret.TouchEvent.TOUCH_TAP, this.HidEndBg, this); //关闭按钮 触发的事件
        this.close.addEventListener(egret.TouchEvent.TOUCH_TAP, this.lianxiFunc, this);//重新练习
        this.photo = new eui.Image("player_png");
        this.photo.width = this.stage.stageWidth / 8;
        this.photo.height = this.stage.stageHeight / 8;
        this.photo.x = this.stage.stageWidth / 2 - this.photo.width / 2 - 80;
        this.photo.y = 50;
        this.addChild(this.photo);
        this.playername = new eui.Label();
        this.playername.text = "Mary";
        this.playername.x = this.stage.stageWidth / 2 - this.photo.width / 2 + 150;
        this.playername.y = 130;
        this.playername.bold = true;
        this.addChild(this.playername);
        var scoretxt: eui.Label;
        scoretxt = new eui.Label();
        scoretxt.text = "得分";
        scoretxt.x = this.stage.stageWidth / 2 - this.photo.width / 2
        scoretxt.y = 230;
        scoretxt.textColor = 0xD9D919;
        scoretxt.bold = true;
        this.addChild(scoretxt);
        this.score = new eui.Label();   //玩家得分
        this.score.text = "" + this.goal;
        this.score.x = this.stage.stageWidth / 2 - this.photo.width / 2
        this.score.y = 310;
        this.score.size = 90;
        this.score.bold = true;
        this.addChild(this.score);
        var Maxscoretxt: eui.Label;
        Maxscoretxt = new eui.Label();
        Maxscoretxt.text = "高分";
        Maxscoretxt.x = this.stage.stageWidth / 2 - this.photo.width / 2
        Maxscoretxt.y = 430;
        Maxscoretxt.textColor = 0xD9D919;
        Maxscoretxt.bold = true;
        this.addChild(Maxscoretxt);
        this.Maxscore = new eui.Label();//玩家最高分
        this.Maxscore.text = "" + this.maxgoal;
        this.Maxscore.size = 75;
        this.Maxscore.x = this.stage.stageWidth / 2 - this.photo.width / 2
        this.Maxscore.y = 510;
        this.Maxscore.bold = true;
        this.addChild(this.Maxscore);
        var ComeOn: eui.Label;
        ComeOn = new eui.Label();
        ComeOn.text = "每个绅士都会打撞球,不过打太好的不算";
        ComeOn.x = this.stage.stageWidth / 2 - 210;
        ComeOn.y = 630;
        ComeOn.size = 25;
        ComeOn.textColor = 0xA68064;
        this.addChild(ComeOn);
        this.retry = new eui.Image("retry_png");
        this.retry.x = this.stage.stageWidth / 2 - 200;
        this.retry.y = 730;
        this.addChild(this.retry);
        this.retry.addEventListener(egret.TouchEvent.TOUCH_TAP, this.HidEndBg, this);  //重开一局 触发的事件
        this.retry.addEventListener(egret.TouchEvent.TOUCH_TAP, this.lianxiFunc, this);//重新练习
        this.share = new eui.Image("share_png");//分享
        this.share.x = this.stage.stageWidth / 2 + 20;
        this.share.y = 730;
        this.addChild(this.share);
        this.share.addEventListener(egret.TouchEvent.TOUCH_TAP, this.Share, this);  //分享游戏 触发的事件
        this.offs = [this.end, this.close, this.photo, this.playername, scoretxt, this.score, Maxscoretxt, this.Maxscore, ComeOn, this.retry, this.share];
    }
    /**
     * 重新开始 隐藏结算界面
     */
    private HidEndBg() {
        for (var i: number = 0; i < this.offs.length; i++) {
            this.offs[i].visible = false;
        }
    }
    /**
     * 分享游戏
     */
    private Share() {

    }

    private SMTOPutBall(msg) {
        if (this.whiteBall && this.whiteBall.parent) {
            this.removeChild(this.whiteBall);
            this.whiteBall = null;
        }
        if (this.xIcon && this.xIcon.parent) {
            this.removeChild(this.xIcon);
            this.xIcon = null;
        }
        if (this.isBaiqiu == 1) {
            this.countdownFunc(true, 15);
        }
        else {
            this.countdownFunc(true, 25);
        }
        this.isBaiqiu = 0;
        this.curBall.isJindong = -1;
        this.curBall.lastX = this.curBall.nextX = Number(msg.ball.x);
        this.curBall.lastY = this.curBall.nextY = Number(msg.ball.y);
        setBaiPos(msg.ball.x, msg.ball.y);
        refreshUI();
    }

    private isTOHit: boolean = false;
    private SMTOHit(msg) {
        this.isTOHit = true;
        this.countdownFunc(false);

        this.ganImg.visible = false;

        this.shp1.graphics.clear();
        this.shp2.graphics.clear();
        this.shp3.graphics.clear();
        this.shp4.graphics.clear();
        this.shp5.graphics.clear();

        for (var i: number = 0; i < this.lightArr.length; i++) {
            if (this.lightArr[i]) {
                this.lightArr[i].animation.gotoAndStop("zq_guang_001a", 0);
                this.removeChild(this.lightArr[i].display);
                dragonBones.WorldClock.clock.remove(this.lightArr[i]);
            }
        }
        this.lightArr = [];

        this.isOwnGame = false;
        this.isMove = true;
        this.isBegin = false;

        this.ganImg0.visible = true;
        this.ganImg1.visible = true;
        this.curBall.vx = 0;
        this.curBall.vy = 0;
        this.isLoading = 2;
        this.addEventListener(egret.Event.ENTER_FRAME, this.enterFrame, this);
    }
    /**落杆倒计时 */
    private countdownFunc(b: boolean, _num: number = 0) {
        if (b && _num > 0) {
            var num = Math.floor(_num);
            this.curTimerNum = num;
            if (!this.countdownTimer.running) {
                this.countdownTimer.start();
            }
        }
        if (!b) {
            this.curTimerNum = 0;
            if (this.countdownTimer.running) {
                this.countdownTimer.stop();
            }
            this.setTimeNum(this.curTimerNum);
        }
    }
    private startCountDown() {
        this.curTimerNum--;
        this.setTimeNum(this.curTimerNum);
        if (this.curTimerNum == 0) {
            this.countdownTimer.stop();
        }
    }

    public againFunc() {
        this.resetUI();

        if (this.isLianxi == 1) {


            var dengdai: eui.Label = new eui.Label();
            dengdai.text = "等待其他玩家...";
            dengdai.width = 1440;
            dengdai.y = this.centerY;
            dengdai.name = "dengdai";
            dengdai.textAlign = egret.HorizontalAlign.CENTER;
            this.addChild(dengdai);
        }
        else if (this.isLianxi == 2) {
            this.isOwnGame = true;

            this.ganImg0.visible = false;
            this.ganImg1.visible = true;

            this.isBaiqiu = 1;

            var dengdai: eui.Label = new eui.Label();
            dengdai.text = "等待游戏开始...";
            dengdai.width = 1440;
            dengdai.y = this.centerY;

            dengdai.name = "dengdai";
            dengdai.textAlign = egret.HorizontalAlign.CENTER;
            this.addChild(dengdai);

            egret.setTimeout(this.startGame1, this, 100);
        }
    }

    //重置界面
    private resetUI() {
        this.removeAllEventListener();

        for (var i: number = this.ballArr.length - 1; i >= 0; i--) {
            remove3DBall(i);
            this.ballArr.splice(i, 1);
        }
        refreshUI();

        Refresh3DBall();

        this.isMove = false;
        this.isBegin = false;
        this.isOwnGame = false;
        this.otherChairId = -1;
        this.curActionNum = 0;
        this.myColor = -1;

        this.smallGroup.visible = false;
        this.bigGroup.visible = false;

        this.leftLabel.visible = false;
        this.rightLabel.visible = false;

        this.leftTurn.visible = false;
        this.rightTurn.visible = false;

        this.ball8.alpha = 0.4;
        this.ball16.alpha = 0.4;
        for (var i: number = 0; i < this.ballImgArr.length; i++) {
            if (this.ballImgArr[i]) {
                this.ballImgArr[i].alpha = 0.4;
            }
        }

        for (var i: number = 0; i < this.lightArr.length; i++) {
            if (this.lightArr[i]) {
                this.lightArr[i].animation.gotoAndStop("zq_guang_001a", 0);
                this.removeChild(this.lightArr[i].display);
                dragonBones.WorldClock.clock.remove(this.lightArr[i]);
            }

        }
        this.lightArr = [];

        this.ganImg.visible = false;
        this.ganImg0.visible = true;
        this.ganImg1.visible = true;

        this.long = 251 * 0.7;
        this.liduLabel.text = "" + 70 + "/100";
        var rect: egret.Rectangle = new egret.Rectangle(251 - this.long, 0, this.long, 42);
        this.lidu.mask = rect;
    }

    private showTips(e: egret.TouchEvent) {
        if (!this.tipsUI.parent) {
            this.tipsUI.anchorOffsetX = 212;
            this.tipsUI.anchorOffsetY = 58;
            this.tipsUI.x = e.target.x;
            this.tipsUI.y = e.target.y;
            this.tipsUI.dingshi();
            this.addChild(this.tipsUI);
        }

    }

    public SMHit(msg) {
        this.countdownFunc(false);
        this.ganImg.visible = false;
        this.ganImg0.visible = true;
        this.ganImg1.visible = true;
        this.curBall.vx = Number(msg.vx);
        this.curBall.vy = Number(msg.vy);
        this.isLoading = 2;
        this.addEventListener(egret.Event.ENTER_FRAME, this.enterFrame, this);
    }

    private static _instance: TableUI = null;

    public static Instance(): TableUI {
        if (TableUI._instance == null) {
            TableUI._instance = new TableUI();
        }
        return TableUI._instance;
    }
    /**鼠标移动杆 */
    private mouseMoveGan(evt: MouseEvent) {
        if (TableUI.Instance().isKsBtn) {
            TableUI.Instance().playKsAction(evt.pageX, evt.pageY);
        }
        if (TableUI.Instance().isCanMove) {
            TableUI.Instance().moveGan(evt.pageX, evt.pageY);
        }

    }
    //posArr
    private isKsPlay: boolean = false;
    /**播放开始动画 */
    private playKsAction(_x: number, _y: number) {
        var mPX: number = 0;
        var mPY: number = 0;
        if (bep == 0) {
            mPX = _rate * _x;
            mPY = _rate * (_y - bel);
        } else if (bep == 1) {
            mPX = _rate * (_x - bel);
            mPY = _rate * _y;
        }
        var _x = this.centerX;
        var _y = this.centerY + 80;
        if (mPX >= _x - 80 && mPY >= _y - 80 && mPX <= _x + 80 && mPY <= _y + 80) {
            if (!this.isKsPlay) {
                this.isKsPlay = true;
                console.log("play");
                this.ksDragon.animation.gotoAndPlay("zq_ks_02a", -1, -1, 0);
            }
        }
        else {
            if (this.isKsPlay) {
                //this.ksDragon.animation.gotoAndStop("zq_ks_02a", 0, 0);

                this.isKsPlay = false;
                console.log("over");
            }
        }
        if (mPX >= this.lianxiImg.x - 48 && mPX <= this.lianxiImg.x + 48 && mPY >= this.lianxiImg.y && mPY <= this.lianxiImg.y + 41) {
            if (this.lianxiImg.source == 'lianxiBtn1') {
                this.lianxiImg.source = 'lianxiBtn2';
            }
        } else {
            if (this.lianxiImg.source == 'lianxiBtn2') {
                this.lianxiImg.source = 'lianxiBtn1';
            }
        }
    }
    //posArr已修改
    private moveGan(_x: number, _y: number) {
        if (!this.isOwnGame) {
            return;
        }

        if (this.isBaiqiu != 0) {
            var mPX: number = 0;
            var mPY: number = 0;
            if (bep == 0) {
                //舞台转本地坐标
                mPX = _rate * _x;
                mPY = _rate * (_y - bel);
            } else if (bep == 1) {
                mPX = _rate * (_x - bel);
                mPY = _rate * _y;
            }
            //if (mPX >= 116 && mPY >= 31 && mPX <= 1311 && mPY <= 683) {
            if (mPX >= 445.5 + this.moveX && mPY >= -183.5 + this.moveY && mPX <= 984.5 + this.moveX && mPY <= 901.5 + this.moveY) {
                if (this.whiteBall == null) {
                    this.whiteBall = new eui.Image("whiteBall");
                    this.whiteBall.anchorOffsetX = 109 / 2;
                    this.whiteBall.anchorOffsetY = 109 / 2;
                    this.addChild(this.whiteBall);

                    this.curBall.lastX = this.curBall.nextX = -17;
                    this.curBall.lastY = this.curBall.nextY = -17;
                    this.curBall.vx = 0;
                    this.curBall.vy = 0;
                    setBaiPos(-17, -17);
                    refreshUI();
                }
                //-----------------------------------------------摆球
                if (this.isBaiqiu == 1) {
                    //if (mPX > 418) {
                    if (mPY < 618) {
                        if (this.xIcon == null) {
                            this.xIcon = new eui.Image("forbid");
                            this.xIcon.anchorOffsetX = 109 / 2;
                            this.xIcon.anchorOffsetY = 109 / 2;
                            this.addChild(this.xIcon);
                        }
                        this.xIcon.x = mPX;
                        this.xIcon.y = mPY;
                    }
                    else {
                        if (this.xIcon && this.xIcon.parent) {
                            this.removeChild(this.xIcon);
                            this.xIcon = null;
                        }
                    }
                }
                this.whiteBall.x = mPX;
                this.whiteBall.y = mPY;
            }
            return;
        }
        if (!this.isMove && !this.isBegin) {
            var mPX: number = 0;
            var mPY: number = 0;
            if (bep == 0) {
                mPX = _rate * _x;
                mPY = _rate * (_y - bel);
            } else if (bep == 1) {
                mPX = _rate * (_x - bel);
                mPY = _rate * _y;
            }
            //if (mPX >= 116 && mPY >= 31 && mPX <= 1311 && mPY <= 683) {
            if (mPX >= 445.5 + this.moveX && mPY >= -183.5 + this.moveY && mPX <= 984.5 + this.moveX && mPY <= 901.5 + this.moveY) {
                var dx: number = mPX - this.curBall.nextX;
                var dy: number = mPY - this.curBall.nextY;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist <= this._r) {
                    return;
                }
                //显示球杆的旋转
                this.showGan(mPX, mPY);
                this.setSubline();

                if (this.isLianxi == 1) {
                    var curTime: number = egret.getTimer();
                    if (curTime - this.moveTime > 1000) {
                        this.moveTime = curTime;


                    }
                }
            }
        }
    }
    //posArr已修改
    public rotationCoord(_x: number, _y: number, __angele) {
        if (__angele == 0) {
            __angele = 0.0001;
        }
        var radian: number = -__angele;
        var a: number = Math.cos(radian) * Math.cos(radian) / Math.sin(radian) + Math.sin(radian);
        var x: number = ((Math.cos(radian) * _x) / Math.sin(radian) - _y) / a;
        // var x:number=Math.cos(radian)*_x-Math.sin(radian)*_y;
        var b: number = Math.cos(radian) + Math.sin(radian) * Math.sin(radian) / Math.cos(radian);
        var y: number = ((Math.sin(radian) * _x) / Math.cos(radian) + _y) / b;
        //var y:number=(Math.sin(radian)*_x+Math.cos(radian)*_y);
        return { x: x, y: y }
    }
    //posArr已修改
    public showGan(_x: number, _y: number) {
        var qx: number = this.curBall.nextX;
        var qy: number = this.curBall.nextY;

        var dx: number = _x;
        var dy: number = _y;

        var _a: number = dx - qx;
        var _b: number = dy - qy;
        var _c: number = Math.sqrt((dx - qx) * (dx - qx) + (dy - qy) * (dy - qy));

        var angle: number = 0;
        if (_a >= 0 && _b <= 0) {
            angle = Math.asin(_a / _c) * 180 / Math.PI - 90;
            this.angleSpeed = Math.asin(_a / _c);
            this.angleNum = 1;
            this.huadongAngle = this.angleSpeed - Math.PI / 2;
            this.ganImg.x = qx - (this.ganLen) * Math.sin(Math.asin(_a / _c));
            this.ganImg.y = qy + (this.ganLen) * Math.cos(Math.asin(_a / _c));
        }
        if (_a > 0 && _b > 0) {
            angle = (Math.asin(_b / _c)) * 180 / Math.PI;
            this.angleSpeed = Math.asin(_b / _c);
            this.angleNum = 2;
            this.huadongAngle = this.angleSpeed;
            this.ganImg.x = qx - (this.ganLen) * Math.cos((Math.asin(_b / _c)));
            this.ganImg.y = qy - (this.ganLen) * Math.sin((Math.asin(_b / _c)));
        }
        if (_b < 0 && _a < 0) {
            angle = Math.asin(_a / _c) * 180 / Math.PI - 90;
            this.angleSpeed = Math.asin(_a / _c);
            this.angleNum = 3;
            this.huadongAngle = this.angleSpeed - Math.PI / 2;
            this.ganImg.x = qx + (this.ganLen) * Math.sin(Math.asin(-_a / _c));
            this.ganImg.y = qy + (this.ganLen) * Math.cos(Math.asin(-_a / _c));
        }
        if (_a < 0 && _b > 0) {
            angle = (-(Math.asin(_b / _c) + 90 * Math.PI / 180)) * 180 / Math.PI - 90;
            this.angleSpeed = Math.asin(_b / _c);
            this.angleNum = 4;
            this.huadongAngle = Math.PI - this.angleSpeed;
            this.ganImg.x = qx + (this.ganLen) * Math.cos(Math.asin(_b / _c));
            this.ganImg.y = qy - (this.ganLen) * Math.sin(Math.asin(_b / _c));
        }
        this.ganImg.rotation = angle;
        this.ganImg.visible = true;
    }

    private isClickLidu: boolean = false;

    /**力度 */
    private liduFunc(e: egret.TouchEvent) {
        if (this.isBegin || this.isMove) {
            return;
        }
        this.long = 251 - e.localX;
        this.liduLabel.text = "" + Math.floor((this.long / 251) * 100) + "/100";
        var rect: egret.Rectangle = new egret.Rectangle(251 - this.long, 0, this.long, 42);
        this.lidu.mask = rect;
        this.isClickLidu = true;
    }
    /**摆球、自由球 */
    private beginFunc(e: egret.TouchEvent) {
        if (!this.isOwnGame) {
            return;
        }
        //if (e.stageX >= 116 && e.stageY >= 31 && e.stageX <= 1311 && e.stageY <= 683) {
        if (e.stageX >= 445.5 + this.moveX && e.stageY >= -183.5 + this.moveY && e.stageX <= 984.5 + this.moveX && e.stageY <= 901.5 + this.moveY) {
            if (this.isBaiqiu != 0) {
                var num: number = 0;
                var str: string = "";
                if (this.isBaiqiu == 1) {
                    num = 618 + this._r;
                    str = "word15";
                }
                else if (this.isBaiqiu == 2) {
                    num = this.posArr[2].y2; //自由球白球放置
                    str = "word14";
                }
                //0不摆球，1摆球，2自由球
                if (e.stageX > this.posArr[0].x1 + this._r && e.stageY < this.posArr[0].y2 - this._r && e.stageX < this.posArr[3].x2 + this._r && e.stageY > num - this._r) {
                    for (var i: number = 0; i < 6; i++) {   //摆放白球时禁止摆放在洞口判定
                        var _hx: number = this.posArr[i].hx;
                        var _hy: number = this.posArr[i].hy;
                        if (e.stageX > _hx - this.holeR && e.stageX < _hx + this.holeR && e.stageY > _hy - this.holeR && e.stageY < _hy + this.holeR) {
                            var dx: number = e.stageX - _hx;
                            var dy: number = e.stageY - _hy;
                            var dist: number = Math.sqrt(dx * dx + dy * dy);
                            if (dist < this.holeR) {
                                this.promptWord.setSour(str);
                                if (!this.promptWord.parent) {
                                    this.addChild(this.promptWord);
                                }
                                return;
                            }
                        }
                    }

                    for (var j: number = 0; j < this.ballArr.length; j++) {
                        var ballA: NewBall = this.ballArr[j];
                        if (ballA.name == "cur") {
                            continue;
                        }
                        var dx: number = ballA.nextX - e.stageX;
                        var dy: number = ballA.nextY - e.stageY;
                        var dist: number = Math.sqrt(dx * dx + dy * dy);
                        if (dist <= 2 * this._r) {
                            this.promptWord.setSour(str);
                            if (!this.promptWord.parent) {
                                this.addChild(this.promptWord);
                            }

                            return;
                        }
                    }

                    if (this.isLianxi == 1) {

                    }
                    setBaiPos(e.stageX, e.stageY);
                    refreshUI();
                    this.curBall.lastX = this.curBall.nextX = e.stageX;
                    this.curBall.lastY = this.curBall.nextY = e.stageY;

                    if (this.whiteBall && this.whiteBall.parent) {
                        this.removeChild(this.whiteBall);
                        this.whiteBall = null;
                    }

                    if (this.xIcon && this.xIcon.parent) {
                        this.removeChild(this.xIcon);
                        this.xIcon = null;
                    }

                    this.curBall.isJindong = -1;
                    if (this.isLianxi == 1) {
                        if (this.isBaiqiu == 1) {
                            this.countdownFunc(true, 15);
                        }
                        else if (this.isBaiqiu == 2) {
                            this.countdownFunc(true, 25);
                        }
                    }
                    this.isBaiqiu = 0;
                }
                else {

                    this.promptWord.setSour(str);
                    if (!this.promptWord.parent) {
                        this.addChild(this.promptWord);
                    }

                    return;
                }

                return;
            }
        }
        //鼠标点击，力度显示
        if (!this.isMove && !this.isBegin) {
            //if (e.stageX >= 116 && e.stageY >= 31 && e.stageX <= 1311 && e.stageY <= 683) {
            if (e.stageX >= 445.5 + this.moveX && e.stageY >= -183.5 + this.moveY && e.stageX <= 984.5 + this.moveX && e.stageY <= 901.5 + this.moveY) {
                var dx: number = e.stageX - this.curBall.nextX;
                var dy: number = e.stageY - this.curBall.nextY;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist <= this._r) {
                    return;
                }



                if (this.isLianxi == 1) {

                }

                this.isBegin = true;
                if (!this.isClickLidu) {
                    this.long = 251 * 0.7;
                }
                else {
                    this.isClickLidu = false;
                }

                this.addNum = 2;

                this.isLoading = 0;
                this.addEventListener(egret.Event.ENTER_FRAME, this.enterFrame, this);
                this.liduTime = egret.setTimeout(function () {
                    this.isLoading = 1;
                }, this, 500);
                return;
            }
        }
    }

    private promptWord: PromptWord;
    private liduTime: number = 0;
    private moveFunc(e: egret.TouchEvent) {

    }
    /**清除辅助线
     * 显示击球动画
     */
    private endFunc() {
        if (!this.isOwnGame) {
            return;
        }
        if (!this.isMove && this.isBegin) {
            var speed: number = 2 * this.long / 251;

            if (this.angleNum == 1) {
                this.curVx = speed * Math.sin(this.angleSpeed);
                this.curVy = -speed * Math.cos(this.angleSpeed);
            }
            else if (this.angleNum == 2) {
                this.curVx = speed * Math.cos(this.angleSpeed);
                this.curVy = speed * Math.sin(this.angleSpeed);
            }
            else if (this.angleNum == 3) {
                this.curVx = speed * Math.sin(this.angleSpeed);
                this.curVy = -speed * Math.cos(this.angleSpeed);
            }
            else if (this.angleNum == 4) {
                this.curVx = -speed * Math.cos(this.angleSpeed);
                this.curVy = speed * Math.sin(this.angleSpeed);
            }

            this.shp1.graphics.clear();
            this.shp2.graphics.clear();
            this.shp3.graphics.clear();
            this.shp4.graphics.clear();
            this.shp5.graphics.clear();

            for (var i: number = 0; i < this.lightArr.length; i++) {
                if (this.lightArr[i]) {
                    this.lightArr[i].animation.gotoAndStop("zq_guang_001a", 0);
                    this.removeChild(this.lightArr[i].display);
                    dragonBones.WorldClock.clock.remove(this.lightArr[i]);
                }
            }
            this.lightArr = [];

            this.curBall.vx = this.curVx;
            this.curBall.vy = this.curVy;

            this.isOwnGame = false;
            this.isMove = true;
            this.isBegin = false;

            if (this.isLianxi == 1) {

            }

            this.countdownFunc(false);

            egret.clearTimeout(this.liduTime);
            this.isLoading = 0;

            var oldx: number = this.ganImg.x;
            var oldy: number = this.ganImg.y;

            var dx: number = this.curBall.nextX - oldx;
            var dy: number = this.curBall.nextY - oldy;
            var angle: number = Math.atan2(dy, dx);
            var sin: number = Math.sin(angle);
            var cos: number = Math.cos(angle);

            var pos0: egret.Point = new egret.Point(0, 0);
            pos0.x -= 80 * this.long / 251;
            var pos0F: any = this.rotateR(pos0.x, pos0.y, sin, cos, false);

            var newOldx = oldx + pos0F.x;
            var newOldy = oldy + pos0F.y;

            var tw = egret.Tween.get(this.ganImg);
            tw.to({ x: newOldx, y: newOldy }, 1000 * (1 - this.long / 251));
            tw.to({ x: oldx, y: oldy }, 600 * (1 - this.long / 251));
            tw.call(function () {
                this.isLoading = 2;
                this.ganImg.visible = false;

                if (this.isLianxi == 1) {
                    this.ganImg0.visible = true;
                }

                this.ganImg1.visible = true;

                var channel: egret.SoundChannel = this.soundganqiu.play(0, 1);
                channel.volume = Math.sqrt(this.curVx * this.curVx + this.curVy * this.curVy) / 2;

            }, this)
        }
    }

    private addNum: number = 2;
    //posArr已修改
    private enterFrame() {
        if (this.isLoading == 1) { //0,空挡，1，是读条，2，是运行
            this.long += this.addNum;
            if (this.long >= 251) {
                this.addNum = -2;
            }
            else if (this.long <= 0) {
                this.addNum = 2;
            }
            var rect: egret.Rectangle = new egret.Rectangle(251 - this.long, 0, this.long, 42);
            this.lidu.mask = rect;
            this.liduLabel.text = "" + Math.floor((this.long / 251) * 100) + "/100";
        }
        else if (this.isLoading == 2) {
            this.updataMask();

            refreshUI();
        }

    }
    /**更新遮罩 */
    private updataMask() {
        for (var u: number = 0; u < 30; u++) {
            var len: number = this.ballArr.length;
            var num: number = 0;
            for (var i: number = len - 1; i >= 0; i--) {
                var ball: NewBall = this.ballArr[i];
                if (ball.vx == 0 && ball.vy == 0 && ball.isJindong == -1) {
                    num++;
                }
                if (ball.isJindong != -1) {
                    var pt: egret.Point = egret.Point.polar(11, ball.degree * Math.PI / 180);
                    ball.nextX = this.posArr[ball.isJindong].hx + pt.x;
                    ball.nextY = this.posArr[ball.isJindong].hy + pt.y;
                    ball.degree += 0.6;
                    if (ball.degree >= 300 && ball.degree < 300.6) {
                        this.jinqiuAction(ball.isJindong);
                    }
                    if (ball.degree >= 600) {
                        this.removeBallArr.push(ball.idx);
                        if (ball.name == "cur") {
                            ball.nextX = -17;
                            ball.nextY = -17;
                            ball.isJindong = -1;
                        }
                        else {
                            remove3DBall(i);
                            this.ballArr.splice(i, 1);

                            if (this.ballImgArr[ball.idx - 1]) {
                                this.ballImgArr[ball.idx - 1].alpha = 1;
                            }
                        }
                    }
                }
                else {
                    if (ball.vx != 0 || ball.vy != 0) {
                        ball.nextX += ball.vx;
                        ball.nextY += ball.vy;
                        ball.startRoll();
                        this.checkWalls(ball);
                    }
                }
            }

            var len: number = this.ballArr.length;
            for (i = 0; i < len - 1; i++) {
                var ballA: NewBall = this.ballArr[i];
                if (ballA.isJindong != -1) {
                    continue;
                }
                for (var j: number = i + 1; j < len; j++) {
                    var ballB: NewBall = this.ballArr[j];
                    if (ballB.isJindong != -1) {
                        continue;
                    }
                    this.checkCollision(ballA, ballB);
                }
            }

            if (len == num) {
                this.isLoading = 0;
                this.removeEventListener(egret.Event.ENTER_FRAME, this.enterFrame, this);

                console.log("回合结束");
                this.long = 251 * 0.7;
                this.liduLabel.text = "" + 70 + "/100";
                var rect: egret.Rectangle = new egret.Rectangle(251 - this.long, 0, this.long, 42);
                this.lidu.mask = rect;
                //--------------------------------------------重置
                for (var i: number = this.ballArr.length - 1; i >= 0; i--) {
                    var b: NewBall = this.ballArr[i];
                    b.moc = 0.9997;
                    b.degree = 0;
                    b.isJindong = -1;
                }

                if (this.isLianxi == 1) {
                    var tableArr: any[] = [];
                    for (var i: number = 0; i < this.ballArr.length; i++) {
                        this.ballArr[i].nextX = Math.round(this.ballArr[i].nextX);
                        this.ballArr[i].nextY = Math.round(this.ballArr[i].nextY);
                    }

                    this.firstCollision = 0;
                    this.removeBallArr = [];
                }
                else if (this.isLianxi == 2) {
                    if (this.ballArr.length == 1) {
                        var winUI: WinUI = new WinUI();
                        winUI.x = this.centerX - 546 / 2;
                        winUI.y = this.centerY - 469 / 2;

                        this.addChild(winUI);
                        winUI.playAction();
                    }
                    else {
                        this.isOwnGame = true;
                    }

                    if (this.curBall.nextX == -17 && this.curBall.nextY == -17) {
                        this.isBaiqiu = 2;
                    }
                }

                this.isMove = false;


                //this.showGan(1000, 100);

                break;
            }
        }

        var len: number = this.ballArr.length;
        for (var i: number = len - 1; i >= 0; i--) {
            var b: NewBall = this.ballArr[i];
            setBallPos(b.nextX, b.nextY, b.lastX, b.lastY, i);

            b.lastX = b.nextX;
            b.lastY = b.nextY;
        }
    }
    /** 进球时创建龙骨动画 参数为进入洞的编号 */
    private jinqiuAction(num: number) {
        var dragonbonesData = RES.getRes("jinqiu3");
        var textureData = RES.getRes("jinqiu2");
        var texture = RES.getRes("jinqiu1");
        var dragonbonesFactory: dragonBones.EgretFactory = new dragonBones.EgretFactory();
        dragonbonesFactory.addDragonBonesData(dragonBones.DataParser.parseDragonBonesData(dragonbonesData));
        dragonbonesFactory.addTextureAtlas(new dragonBones.EgretTextureAtlas(texture, textureData));
        var armature: dragonBones.Armature = dragonbonesFactory.buildArmature("armatureName");
        this.addChild(armature.display);
        armature.display.x = this.posArr[num].hx;
        armature.display.y = this.posArr[num].hy;
        dragonBones.WorldClock.clock.add(armature);

        armature.addEventListener(egret.Event.COMPLETE, function () {
            dragonBones.WorldClock.clock.remove(armature);
            if (armature.display.parent) {
                this.removeChild(armature.display);
            }

        }.bind(this), this);
        armature.animation.gotoAndPlay("01", -1, -1, 1);
        // console.log("进球数", this.iii++); 
    }
   
    private checkWalls(b: NewBall) { //检查6个洞及墙的碰撞
        for (var i: number = 0; i < 6; i++) {
            var _hx: number = this.posArr[i].hx;
            var _hy: number = this.posArr[i].hy;
            if (b.nextX > _hx - this.holeR && b.nextX < _hx + this.holeR && b.nextY > _hy - this.holeR && b.nextY < _hy + this.holeR) {
                var dx: number = b.nextX - _hx;
                var dy: number = b.nextY - _hy;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this.holeR) {
                    console.log("进球号： " + b.idx);
                    console.log("进球总数：", this.iii++);
                    if (b.idx != 0) {
                        this.scoreiii += 15; //进彩球得分
                    } else {
                        this.scoreiii -= 10; //进白球减分
                    }
                    this.scoretext.text = "" + this.scoreiii;//实时更新
                    var channel: egret.SoundChannel = this.soundrudong.play(0, 1);
                    channel.volume = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;

                    b.vx = 0;
                    b.vy = 0;
                    b.isJindong = i;
                }
            }
        }
        //左边
        if (b.nextX < this.posArr[0].x1 + this._r) {
            if (b.nextY < this.posArr[0].y1 && b.nextY > this.posArr[1].y1) {//确认碰撞到0-1号洞上边界
                b.nextX = this.posArr[0].x1 + this._r;
                var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);
                channel.volume = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
                b.vx *= this.bounce;
            }
            if (b.nextY < this.posArr[1].y2 && b.nextY > this.posArr[2].y1) {//确认碰撞到1-2号洞上边界
                b.nextX = this.posArr[0].x1 + this._r;
                var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);
                channel.volume = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
                b.vx *= this.bounce;
            }
            if (b.nextY >= this.posArr[0].y1) {//球碰撞进0号洞
                var dx: number = b.nextX - this.posArr[0].x1;
                var dy: number = b.nextY - this.posArr[0].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.rebound(b, this.posArr[0].x1, this.posArr[0].y1, 0.7);
                }
            }
            if (b.nextY <= this.posArr[1].y1 && b.nextY > this.posArr[1].hy) {//球碰撞进1号洞左边

                var dx: number = b.nextX - this.posArr[1].x1;
                var dy: number = b.nextY - this.posArr[1].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.rebound(b, this.posArr[1].x1, this.posArr[1].y1, 0.7);
                }
            }
            if (b.nextY >= this.posArr[1].y2 && b.nextY < this.posArr[1].hy) {//球碰撞进1号洞右边

                var dx: number = b.nextX - this.posArr[1].x2;
                var dy: number = b.nextY - this.posArr[1].y2;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.rebound(b, this.posArr[1].x2, this.posArr[1].y2, 0.7);
                }
            }
            if (b.nextY >= this.posArr[2].y1) {//球碰撞进2号洞

                var dx: number = b.nextX - this.posArr[2].x1;
                var dy: number = b.nextY - this.posArr[2].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.rebound(b, this.posArr[2].x1, this.posArr[2].y1, 0.7);
                }
            }

        }
        //右边
        if (b.nextX > this.posArr[3].x2 - this._r) {
            if (b.nextY < this.posArr[3].y2 && b.nextY > this.posArr[4].y1) {
                b.nextX = this.posArr[3].x2 - this._r;
                var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);
                channel.volume = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
                b.vx *= this.bounce;
            }
            if (b.nextY < this.posArr[4].y2 && b.nextY > this.posArr[5].y2) {
                b.nextX = this.posArr[3].x2 - this._r;
                var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);
                channel.volume = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;
                b.vx *= this.bounce;
            }
            if (b.nextY <= this.posArr[3].y2) {
                var dx: number = b.nextX - this.posArr[3].x2;
                var dy: number = b.nextY - this.posArr[3].y2;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.rebound(b, this.posArr[3].x2, this.posArr[3].y2, 0.7);
                }
            }
            if (b.nextX <= this.posArr[4].y1 && b.nextX > this.posArr[4].hy) {
                var dx: number = b.nextX - this.posArr[4].x1;
                var dy: number = b.nextY - this.posArr[4].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.rebound(b, this.posArr[4].x1, this.posArr[4].y1, 0.7);
                }
            }
            if (b.nextX >= this.posArr[4].y2 && b.nextX < this.posArr[4].hy) {
                var dx: number = b.nextX - this.posArr[4].x2;
                var dy: number = b.nextY - this.posArr[4].y2;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.rebound(b, this.posArr[4].x2, this.posArr[4].y2, 0.7);
                }
            }
            if (b.nextX >= this.posArr[5].y1) {
                var dx: number = b.nextX - this.posArr[5].x1;
                var dy: number = b.nextY - this.posArr[5].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.rebound(b, this.posArr[5].x1, this.posArr[5].y1, 0.7);
                }
            }
        }
        //上边
        if (b.nextY < this.posArr[2].y2 + this._r) {
            if (b.nextX > this.posArr[2].x1 && b.nextX < this.posArr[5].x1) {
                b.nextY = this.posArr[2].y2 + this._r;

                var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);
                channel.volume = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;

                b.vy *= this.bounce;
                return false;
            }
            if (b.nextY <= this.posArr[2].y2) {
                var dx: number = b.nextX - this.posArr[2].x2;
                var dy: number = b.nextY - this.posArr[2].y2;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.rebound(b, this.posArr[2].x2, this.posArr[2].y2, 0.7);
                }
            }
            if (b.nextY >= this.posArr[5].y1) {
                var dx: number = b.nextX - this.posArr[5].x1;
                var dy: number = b.nextY - this.posArr[5].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.rebound(b, this.posArr[5].x1, this.posArr[5].y1, 0.7);
                }
            }
        }
        //下边
        if (b.nextY > this.posArr[0].y2 - this._r) {
            if (b.nextX > this.posArr[0].x2 && b.nextX < this.posArr[3].x1) {
                b.nextY = this.posArr[0].y2 - this._r;

                var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);
                channel.volume = Math.sqrt(b.vx * b.vx + b.vy * b.vy) / 2;

                b.vy *= this.bounce;
                return false;
            }
            if (b.nextY <= this.posArr[0].y2) {
                var dx: number = b.nextX - this.posArr[0].x2;
                var dy: number = b.nextY - this.posArr[0].y2;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.rebound(b, this.posArr[0].x2, this.posArr[0].y2, 0.7);
                }
            }
            if (b.nextY >= this.posArr[3].y1) {
                var dx: number = b.nextX - this.posArr[3].x1;
                var dy: number = b.nextY - this.posArr[3].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.rebound(b, this.posArr[3].x1, this.posArr[3].y1, 0.7);
                }
            }
        }
    }

    //划线部分，posArr已修改
    private setSubline() {
        var v: number = 2;

        var vx: number = 0;
        var vy: number = 0;

        //计算球的速度
        if (this.angleNum == 1) {
            vx = v * Math.sin(this.angleSpeed);
            vy = -v * Math.cos(this.angleSpeed);
        }
        else if (this.angleNum == 2) {
            vx = v * Math.cos(this.angleSpeed);
            vy = v * Math.sin(this.angleSpeed);
        }
        else if (this.angleNum == 3) {
            vx = v * Math.sin(this.angleSpeed);
            vy = -v * Math.cos(this.angleSpeed);
        }
        else if (this.angleNum == 4) {
            vx = -v * Math.cos(this.angleSpeed);
            vy = v * Math.sin(this.angleSpeed);
        }

        this.shp1.graphics.clear();
        this.shp2.graphics.clear();
        this.shp3.graphics.clear();
        this.shp4.graphics.clear();
        this.shp5.graphics.clear();

        var px: number = this.curBall.nextX;
        var py: number = this.curBall.nextY;
     
        let pos = new Point(px,py);
        let velocity = new Point(vx,vy);
       if( !this.CollisionDetection(pos,velocity))
       {
           this.CollisionDetection(pos,velocity,false);
       }
    }

    //旋转向量
    private rotateR(x: number, y: number, sin: number, cos: number, reverse: Boolean): egret.Point {
        var result: egret.Point = new egret.Point();
        if (reverse) {
            result.x = x * cos + y * sin;
            result.y = y * cos - x * sin;
        } else {
            result.x = x * cos - y * sin;
            result.y = y * cos + x * sin;
        }
        return result;
    }

    private checkCollision(ball0: NewBall, ball1: NewBall) {
        var dx: number = ball1.nextX - ball0.nextX;
        var dy: number = ball1.nextY - ball0.nextY;
        var dist: number = Math.sqrt(dx * dx + dy * dy);
        if (dist < 2 * this._r) {

            var _vxx: number = ball0.vx + ball1.vx;
            var _vyy: number = ball0.vy + ball1.vy;
            var channel: egret.SoundChannel = this.soundzhuangqiu.play(0, 1);
            channel.volume = Math.sqrt(_vxx * _vxx + _vyy * _vyy) / 2;

            var angle: number = Math.atan2(dy, dx);
            var sin: number = Math.sin(angle);
            var cos: number = Math.cos(angle);

            var pos0: egret.Point = new egret.Point(0, 0);
            var pos1: egret.Point = this.rotateR(dx, dy, sin, cos, true);

            var vel0: egret.Point = this.rotateR(ball0.vx, ball0.vy, sin, cos, true);
            var vel1: egret.Point = this.rotateR(ball1.vx, ball1.vy, sin, cos, true);

            var overlap: number = 2 * this._r - Math.abs(pos0.x - pos1.x);

            pos0.x -= 0.5 * overlap + 0.0001;
            pos1.x += 0.5 * overlap + 0.0001;

            var pos0F: any = this.rotateR(pos0.x, pos0.y, sin, cos, false);
            var pos1F: any = this.rotateR(pos1.x, pos1.y, sin, cos, false);
            ball1.nextX = ball0.nextX + pos1F.x;
            ball1.nextY = ball0.nextY + pos1F.y;
            ball0.nextX = ball0.nextX + pos0F.x;
            ball0.nextY = ball0.nextY + pos0F.y;

            var vxTotal: number = vel0.x - vel1.x;
            vel0.x = vel1.x;
            vel1.x = vxTotal + vel0.x;

            var vel0F: any = this.rotateR(vel0.x, vel0.y, sin, cos, false);
            var vel1F: any = this.rotateR(vel1.x, vel1.y, sin, cos, false);
            ball0.vx = vel0F.x;
            ball0.vy = vel0F.y;
            ball1.vx = vel1F.x;
            ball1.vy = vel1F.y;
            if (this.firstCollision == 0) {
                if (ball0.idx == 0) {
                    this.firstCollision = ball1.idx;
                }
                if (ball1.idx == 0) {
                    this.firstCollision = ball0.idx;
                }
            }
        }
    }
    
    // 碰撞的位置x,y   bound 弹性

    private reboundDraw(ballPos:Point ,velocity:Point,  holePosX:number,holePosY:number, bound:number)
    {
        if(bound == 0)
        {
            velocity.x = 0;
            velocity.y = 0;
            return;
        }
        let holePos = new Point ( holePosX,holePosY);
        //洞坐标相对球的位置
        let relativeWorldHolePos:Point =Point.sub( holePos, ballPos); 
        var angle: number = Math.atan2(relativeWorldHolePos.y, relativeWorldHolePos.y);
        var sin: number = Math.sin(angle);
        var cos: number = Math.cos(angle);

        var localTouchtPos: egret.Point = new egret.Point(0, 0);  
        var localHolePos = this.rotateR(relativeWorldHolePos.x, relativeWorldHolePos.y, sin, cos, true);
        localTouchtPos.x = localHolePos.x - this._r - 0.0001;
        var relativeWorldTouchPos: any = this.rotateR(localTouchtPos.x, localTouchtPos.y, sin, cos, false);
        ballPos.x  = ballPos.x + relativeWorldTouchPos.x;
        ballPos.y =  ballPos.x + relativeWorldTouchPos.x;
      
        velocity.x = velocity.x*bound;
        velocity.y = velocity.y*bound;

    }
    private rebound(ball0: NewBall, _x, _y, num) {
        if (num == 0) {
            ball0.vx = 0;
            ball0.vy = 0;
            return;
        }

        var channel: egret.SoundChannel = this.soundzhuangbian.play(0, 1);
        channel.volume = Math.sqrt(ball0.vx * ball0.vx + ball0.vy * ball0.vy) / 2;

        var dx: number = _x - ball0.nextX;
        var dy: number = _y - ball0.nextY;
        var angle: number = Math.atan2(dy, dx);
        var sin: number = Math.sin(angle);
        var cos: number = Math.cos(angle);

        var pos0: egret.Point = new egret.Point(0, 0);
        var pos1: egret.Point = this.rotateR(dx, dy, sin, cos, true);  //碰撞点在新坐标系下的位置
        pos0.x = pos1.x - this._r - 0.0001;
        var pos0F: any = this.rotateR(pos0.x, pos0.y, sin, cos, false);
        ball0.nextX = ball0.nextX + pos0F.x;
        ball0.nextY = ball0.nextY + pos0F.y;

        var vel0: egret.Point = this.rotateR(ball0.vx, ball0.vy, sin, cos, true);
        var vel1: egret.Point = this.rotateR(0, 0, sin, cos, true);
        var vxTotal: number = vel0.x - vel1.x;
        vel0.x = vel1.x;
        vel1.x = vxTotal + vel0.x;
        var vel0F: any = this.rotateR(vel0.x, vel0.y, sin, cos, false);
        var vel1F: any = this.rotateR(vel1.x, vel1.y, sin, cos, false);
        ball0.vx = num * (vel0F.x - vel1F.x);
        ball0.vy = num * (vel0F.y - vel1F.y);
    }

    private setTimeNum(_num: number) {
        if (_num < 0 || _num >= 100) {
            return;
        }
        var num: number = Math.floor(_num);
        var leftNum: number = Math.floor(num / 10);
        var rightNum: number = num - leftNum * 10;

        this.leftNumImg.source = "num" + leftNum;
        this.rightNumImg.source = "num" + rightNum;
    }


    private BrokenLine() {

    }
    private reflex(pos1: number[], pos2: number[]) {
        this.shp5.graphics.lineStyle(3, 0xFFFFFF);
        this.shp5.graphics.moveTo(pos1[0], pos1[1]);//起点
        this.shp5.graphics.lineTo(pos2[0], pos2[1]);//终点
        this.shp5.graphics.endFill();
    }
    private debugDrawLine(pos1: number[], pos2: number[]) {
        let shp5 = new egret.Shape;
        this.addChild(shp5);
        shp5.graphics.lineStyle(3, 0xFFFFFF);
        shp5.graphics.moveTo(pos1[0], pos1[1]);//起点
        shp5.graphics.lineTo(pos2[0], pos2[1]);//终点
        shp5.graphics.endFill();
    }
    private debugDrawPoint(pos1: number[]) {
        let shp5 = new egret.Shape;
        this.addChild(shp5);
        shp5.graphics.lineStyle(3, 0xFFFFFF);
        shp5.graphics.drawCircle(pos1[0], pos1[1], this.holeR);
        shp5.graphics.endFill();
    }


    /**
     * posArr已修改
     * px:第一个白圆圈的X坐标py:第一个白圆圈的Y坐标companyX:折线的单位X坐标companyY:折线的单位Y坐标
     * 划折线部分
     */
    private CollisionDetection(pos:Point,veloctity:Point, isfirst:boolean = true):boolean 
    {
        var isImpactWithBall: boolean = false;
        var isImpactWithLeft: boolean = false;
        var isImpactWithRight: boolean = false;
        var isImpactWithTop: boolean = false;
        var isImpactWithBottom: boolean = false;
        var isEnterHole:boolean =false;
        var px = pos.x;
        var py = pos.y;
        var vx = veloctity.x;
        var vy = veloctity.y;
        var orignrX = px;
        var orignrY = py;
           //每一步计算划线的下一点
        for (var i: number = 0; i < 1500; i++) { //以一个单位的大小进行移动 每个点判断是否碰到东西 碰到则退出
            px += vx;
            py += vy;
            //遍历所有的球
            for (var j: number = 0; j <  this.ballArr.length; j++) { //遍历所有彩球
                var ballA: NewBall = this.ballArr[j];
                if (ballA.name == "cur") {
                    continue;
                }
                var dx: number = ballA.nextX - px;//px是白球的坐标 nextX是其他球的坐标   (i倍的)vx
                var dy: number = ballA.nextY - py; // (i倍的)vy
                var dist: number = Math.sqrt(dx * dx + dy * dy);//两球之间的距离  （勾股定理求斜边）


                //距离<球的半径，代表碰到球了

                if (dist <= 2 * this._r) {//小于直径碰撞 （撞到了彩球）
                    isImpactWithBall = true;
                    var a1: any = this.rotationCoord(px, py, this.huadongAngle);
                    var a2: any = this.rotationCoord(ballA.nextX, ballA.nextY, this.huadongAngle);

                    var dx0: number = a1.x - a2.x;
                    var dy0: number = a1.y - a2.y;
                    var dist0: number = Math.sqrt(dx0 * dx0 + dy0 * dy0);
                    var asd: number = Math.abs(dx0 / dist0);
                    var num: number = dy0 / Math.abs(dy0);

                    //计算两点之间的X与Y轴的距离计算出来两点之间的斜率角度
                    var angle: number = Math.atan2(dy, dx);
                    var sin: number = Math.sin(angle);
                    var cos: number = Math.cos(angle);
                    var pos1: egret.Point = this.rotateR(dx, dy, sin, cos, true);

                    pos1.x += 70 * asd;

                    var pos2: egret.Point = new egret.Point(0, num * (this._r + 50 * (1 - asd)));

                    var pos3: egret.Point = new egret.Point(0, num * this._r);

                    var pos1F: any = this.rotateR(pos1.x, pos1.y, sin, cos, false);

                    var pos2F: any = this.rotateR(pos2.x, pos2.y, sin, cos, false);

                    var pos3F: any = this.rotateR(pos3.x, pos3.y, sin, cos, false);

                    this.shp1.graphics.lineStyle(3, 0xFFFFFF);//白球第一条瞄准线
                    this.shp1.graphics.moveTo(orignrX, orignrY);
                    this.shp1.graphics.lineTo(px, py);
                    this.shp1.graphics.endFill();

                    this.shp3.graphics.lineStyle(3, 0xFF0000);//红线 （碰到的彩球走向）
                    this.shp3.graphics.moveTo(ballA.nextX, ballA.nextY);
                    this.shp3.graphics.lineTo(px + pos1F.x, py + pos1F.y);
                    this.shp3.graphics.endFill();

                    this.shp4.graphics.lineStyle(3, 0x0000FF);//蓝线 （白球走向）
                    this.shp4.graphics.moveTo(px, py);//起点
                    this.shp4.graphics.lineTo(px + pos2F.x, py + pos2F.y);//终点
                    this.shp4.graphics.endFill();
                    this.shp2.graphics.lineStyle(3, 0xFFFFFF);
                    this.shp2.graphics.drawCircle(px, py, this._r - 2);
                    this.shp2.graphics.endFill();

                    break;
                }
            }
            if (isImpactWithBall) {//撞到了彩球退出1500递增
                break;
            }

            //进洞检测
            for (var i: number = 0; i < 6; i++) {
                var _hx: number = this.posArr[i].hx;
                var _hy: number = this.posArr[i].hy;
                if (px > _hx - this.holeR && px< _hx + this.holeR && py > _hy - this.holeR && py  < _hy + this.holeR) {
                  isEnterHole = true;
                  break;
                }
            }
            
            if(isEnterHole)
            {
                break;
            }
            isImpactWithLeft =  this.CheckLeftDraw(px,py,pos,veloctity);
            if(isImpactWithLeft)
            {
                break;
            }
            isImpactWithRight =  this.CheckRightDraw(px,py,pos,veloctity);
            if(isImpactWithRight)
            {
                break;
            }
            isImpactWithTop =  this.CheckTopDraw(px,py,pos,veloctity);
            if(isImpactWithTop)
            {
                break;
            }
            isImpactWithBottom =  this.CheckBottomDraw(px,py,pos,veloctity);
            if(isImpactWithBottom)
            {
                break;
            }

         
        
           

            if (px < this.posArr[0].x1 - this._r*2) {
                break;
            }
            if (px > this.posArr[5].x2 + this._r*6) {
                break;
            }
            if (py < this.posArr[2].y2 - this._r*2) {
                break;
            }
            if (py > this.posArr[3].y1 + this._r*6) {
                break;
            }
        }//1500结束

        if(isImpactWithLeft||isImpactWithRight|| isImpactWithTop|| isImpactWithBottom)
        {
            this.shp1.graphics.lineStyle(3, 0xFFFFFF);//白球第一条瞄准线
            this.shp1.graphics.moveTo(orignrX, orignrY);
            this.shp1.graphics.lineTo(pos.x, pos.y);
            this.shp1.graphics.endFill();
                
            if(!isfirst)
            {
                this.shp2.graphics.lineStyle(3, 0xFFFFFF);
                this.shp2.graphics.drawCircle(pos.x, pos.y, this._r - 2);
                this.shp2.graphics.endFill();
            }
            return false;
        }
        if(isImpactWithBall || isEnterHole)
            return true;
        return true;
    }

    //zhijiang的代码

    /**对posArr进行调整 */
    private AdjustposArr() {
        /**洞纵长 */
        let holeL: number = Math.abs(this.posArr[0].y1 - this.posArr[0].y2);
        /**洞横跨 */
        let holeB: number = Math.abs(this.posArr[0].x1 - this.posArr[0].x2);

        //调整一号洞坐标
        this.posArr[1].hx = this.posArr[0].hx + this.TableB * 0;
        this.posArr[1].hy = this.posArr[0].hy + this.TableL * -0.5;

        this.posArr[1].x1 = this.posArr[0].x1 + holeB * 0;
        this.posArr[1].y1 = this.posArr[1].hy + holeL * 0.5;

        this.posArr[1].x2 = this.posArr[0].x1 + holeB * 0;
        this.posArr[1].y2 = this.posArr[1].hy + holeL * -0.5;


        //调整二号洞坐标
        this.posArr[2].hx = this.posArr[0].hx + this.TableB * 0;
        this.posArr[2].hy = this.posArr[0].hy + this.TableL * -1;

        this.posArr[2].x1 = this.posArr[2].hx + holeB * -0.5;
        this.posArr[2].y1 = this.posArr[2].hy + holeL * 0.5;

        this.posArr[2].x2 = this.posArr[2].hx + holeB * 0.5;
        this.posArr[2].y2 = this.posArr[2].hy + holeL * -0.5;

        //调整三号洞坐标
        this.posArr[3].hx = this.posArr[0].hx + this.TableB * 1;
        this.posArr[3].hy = this.posArr[0].hy + this.TableL * 0;

        this.posArr[3].x1 = this.posArr[3].hx + holeB * -0.5;
        this.posArr[3].y1 = this.posArr[3].hy + holeL * 0;

        this.posArr[3].x2 = this.posArr[3].hx + holeB * 0.5;
        this.posArr[3].y2 = this.posArr[3].hy + holeL * -1;

        //调整四号洞坐标
        this.posArr[4].hx = this.posArr[0].hx + this.TableB * 1;
        this.posArr[4].hy = this.posArr[0].hy + this.TableL * -0.5;

        this.posArr[4].x1 = this.posArr[3].x2 + holeB * 0;
        this.posArr[4].y1 = this.posArr[4].hy + holeL * 0.5;

        this.posArr[4].x2 = this.posArr[3].x2 + holeB * 0;
        this.posArr[4].y2 = this.posArr[4].hy + holeL * -0.5;


        //调整五号洞坐标
        this.posArr[5].hx = this.posArr[0].hx + this.TableB * 1;
        this.posArr[5].hy = this.posArr[0].hy + this.TableL * -1;

        this.posArr[5].x1 = this.posArr[5].hx + holeB * 0.5;
        this.posArr[5].y1 = this.posArr[5].hy + holeL * 0.5;

        this.posArr[5].x2 = this.posArr[5].hx + holeB * -0.5;
        this.posArr[5].y2 = this.posArr[5].hy + holeL * -0.5;


        var pos = new Array(2);
        pos[0] = this.posArr[0].x1;
        pos[1] = this.posArr[0].y1;

        var pos0 = new Array(2);
        pos0[0] = this.posArr[0].x2;
        pos0[1] = this.posArr[0].y2;

        var pos01 = new Array(2);
        pos01[0] = this.posArr[1].x1;
        pos01[1] = this.posArr[1].y1;

        var pos001 = new Array(2);
        pos001[0] = this.posArr[1].x2;
        pos001[1] = this.posArr[1].y2;

        var pos1 = new Array(2);
        pos1[0] = this.posArr[2].x1;
        pos1[1] = this.posArr[2].y1;

        var pos2 = new Array(2);
        pos2[0] = this.posArr[2].x2;
        pos2[1] = this.posArr[2].y2;

        var pos3 = new Array(2);
        pos3[0] = this.posArr[3].x1;
        pos3[1] = this.posArr[3].y1;

        var pos4 = new Array(2);
        pos4[0] = this.posArr[3].x2;
        pos4[1] = this.posArr[3].y2;

        var pos5 = new Array(2);
        pos5[0] = this.posArr[4].x1;
        pos5[1] = this.posArr[4].y1;

        var pos6 = new Array(2);
        pos6[0] = this.posArr[4].x2;
        pos6[1] = this.posArr[4].y2;

        var pos7 = new Array(2);
        pos7[0] = this.posArr[5].x1;
        pos7[1] = this.posArr[5].y1;

        var pos8 = new Array(2);
        pos8[0] = this.posArr[5].x2;
        pos8[1] = this.posArr[5].y2;

        //洞
        this.debugDrawLineWithColor(pos, pos0, 0xaaa00a);       //土黄 0洞
        this.debugDrawLineWithColor(pos01, pos001, 0xaaFF0a);   //黄绿 1洞
        this.debugDrawLineWithColor(pos1, pos2, 0x00FFFF);      //青   2洞
        this.debugDrawLineWithColor(pos3, pos4, 0xFF00FF);      //紫   3洞
        this.debugDrawLineWithColor(pos5, pos6, 0x0000FF);      //蓝   4洞
        this.debugDrawLineWithColor(pos7, pos8, 0xFF0000);      //红   5洞

        //墙
        this.debugDrawLineWithColor(pos, pos01, 0xFFFFFF);//1
        this.debugDrawLineWithColor(pos001, pos1, 0xFFFFFF);//2
        this.debugDrawLineWithColor(pos2, pos8, 0xFFFFFF);//3
        this.debugDrawLineWithColor(pos7, pos6, 0xFFFFFF);//4
        this.debugDrawLineWithColor(pos5, pos4, 0xFFFFFF);//5
        this.debugDrawLineWithColor(pos3, pos0, 0xFFFFFF);//6

        //画案

        var r1 = new Array(2);
        r1[0] = this.posArr[0].hx;
        r1[1] = this.posArr[0].hy;

        var r2 = new Array(2);
        r2[0] = this.posArr[2].hx;
        r2[1] = this.posArr[2].hy;

        var r3 = new Array(2);
        r3[0] = this.posArr[5].hx;
        r3[1] = this.posArr[5].hy;

        var r4 = new Array(2);
        r4[0] = this.posArr[3].hx;
        r4[1] = this.posArr[3].hy;

        this.debugDrawLineWithColor(r1, r2, 0xAAAAAA);
        this.debugDrawLineWithColor(r2, r3, 0xcccccc);
        this.debugDrawLineWithColor(r3, r4, 0xeeeeee);
        this.debugDrawLineWithColor(r4, r1, 0xdddddd);


    }




    //带色划线
    private debugDrawLineWithColor(pos1: number[], pos2: number[], color: number) {
        let sh = new egret.Shape;
        this.addChild(sh);
        sh.graphics.lineStyle(3, color);
        sh.graphics.moveTo(pos1[0], pos1[1]);//起点
        sh.graphics.lineTo(pos2[0], pos2[1]);//终点
        sh.graphics.endFill();
    }

    //带色划圈
    private debugDrawPointWthColor(pos1: number[], color) {
        let sh = new egret.Shape;
        this.addChild(sh);
        sh.graphics.lineStyle(3, color);
        sh.graphics.drawCircle(pos1[0], pos1[1], 20);
        sh.graphics.endFill();
    }
    private debugDrawTable() {
      var pos1 = new Array(2);
        pos1[0] = this.posArr[0].hx;
        pos1[1] = this.posArr[0].hy;
        var pos2 = new Array(2);
        pos2[0] = this.posArr[1].hx;
        pos2[1] = this.posArr[1].hy;
        var pos3 = new Array(2);
        var pos4 = new Array(2);
        pos3[0] = this.posArr[2].hx;
        pos3[1] = this.posArr[2].hy;
        pos4[0] = this.posArr[3].hx;
        pos4[1] = this.posArr[3].hy;
        var pos5 = new Array(2);
        var pos6 = new Array(2);
        pos5[0] = this.posArr[4].hx;
        pos5[1] = this.posArr[4].hy;
        pos6[0] = this.posArr[5].hx;
        pos6[1] = this.posArr[5].hy;


        this.debugDrawPoint(pos1);
        this.debugDrawPointWthColor(pos1,0x880000);
        this.debugDrawPoint(pos2);
        this.debugDrawPointWthColor(pos2,0xff0000);
        this.debugDrawPoint(pos3);
        this.debugDrawPointWthColor(pos3,0x008800);
        this.debugDrawPoint(pos4);
        this.debugDrawPointWthColor(pos4,0x00ff00);
        this.debugDrawPoint(pos5);
        this.debugDrawPointWthColor(pos5,0x000088);
        this.debugDrawPoint(pos6);
        this.debugDrawPointWthColor(pos6,0x0000ff);
    
        var edgePos11:Point = new Point(this.posArr[0].x1,this.posArr[0].y1);
        var edgePos12:Point = new Point(this.posArr[0].x2,this.posArr[0].y2);
        var edgePos13:Point = new Point(this.posArr[0].x3,this.posArr[0].y3);
        var edgePos14:Point = new Point(this.posArr[0].x4,this.posArr[0].y4);

        this.debugDrawPointWthColor([edgePos11.x,edgePos11.y],0x880000);
        this.debugDrawPointWthColor([edgePos12.x,edgePos12.y],0xFFFFFF);
        this.debugDrawPointWthColor([edgePos13.x,edgePos13.y],0xFF0000);
        this.debugDrawPointWthColor([edgePos14.x,edgePos14.y],0xFFFFFF);
        this.debugDrawLineWithColor([edgePos11.x,edgePos11.y], [edgePos14.x,edgePos14.y],0xFFFF00);
        this.debugDrawLineWithColor([edgePos12.x,edgePos12.y], [edgePos13.x,edgePos13.y],0x00FFFF);
     

        var edgePos21:Point = new Point(this.posArr[1].x1,this.posArr[1].y1);
        var edgePos22:Point = new Point(this.posArr[1].x2,this.posArr[1].y2);
        var edgePos23:Point = new Point(this.posArr[1].x3,this.posArr[1].y3);
        var edgePos24:Point = new Point(this.posArr[1].x4,this.posArr[1].y4);

        this.debugDrawPointWthColor([edgePos21.x,edgePos21.y],0x008800);
        this.debugDrawPointWthColor([edgePos22.x,edgePos22.y],0xFFFFFF);
        this.debugDrawPointWthColor([edgePos23.x,edgePos23.y],0x00FF00);
        this.debugDrawPointWthColor([edgePos24.x,edgePos24.y],0xFFFFFF);
        this.debugDrawLineWithColor([edgePos21.x,edgePos21.y], [edgePos24.x,edgePos24.y],0xFFFF00);
        this.debugDrawLineWithColor([edgePos22.x,edgePos22.y], [edgePos23.x,edgePos23.y],0x00FFFF);

        var edgePos31:Point = new Point(this.posArr[2].x1,this.posArr[2].y1);
        var edgePos32:Point = new Point(this.posArr[2].x2,this.posArr[2].y2);
        var edgePos33:Point = new Point(this.posArr[2].x3,this.posArr[2].y3);
        var edgePos34:Point = new Point(this.posArr[2].x4,this.posArr[2].y4);

        this.debugDrawPointWthColor([edgePos31.x,edgePos31.y],0x000088);
        this.debugDrawPointWthColor([edgePos32.x,edgePos32.y],0xFFFFFF);
        this.debugDrawPointWthColor([edgePos33.x,edgePos33.y],0x0000FF);
        this.debugDrawPointWthColor([edgePos34.x,edgePos34.y],0xFFFFFF);
        this.debugDrawLineWithColor([edgePos31.x,edgePos31.y], [edgePos33.x,edgePos33.y],0xFFFF00);
        this.debugDrawLineWithColor([edgePos32.x,edgePos32.y], [edgePos34.x,edgePos34.y],0x00FFFF);

     
        var edgePos41:Point = new Point(this.posArr[3].x1,this.posArr[3].y1);
        var edgePos42:Point = new Point(this.posArr[3].x2,this.posArr[3].y2);
        var edgePos43:Point = new Point(this.posArr[3].x3,this.posArr[3].y3);
        var edgePos44:Point = new Point(this.posArr[3].x4,this.posArr[3].y4);

        this.debugDrawPointWthColor([edgePos41.x,edgePos41.y],0x880000);
        this.debugDrawPointWthColor([edgePos42.x,edgePos42.y],0xFFFFFF);
        this.debugDrawPointWthColor([edgePos43.x,edgePos43.y],0xFF0000);
        this.debugDrawPointWthColor([edgePos44.x,edgePos44.y],0xFFFFFF);
        this.debugDrawLineWithColor([edgePos41.x,edgePos41.y], [edgePos43.x,edgePos43.y],0xFFFF00);
        this.debugDrawLineWithColor([edgePos42.x,edgePos42.y], [edgePos44.x,edgePos44.y],0x00FFFF);


        var edgePos51:Point = new Point(this.posArr[4].x1,this.posArr[4].y1);
        var edgePos52:Point = new Point(this.posArr[4].x2,this.posArr[4].y2);
        var edgePos53:Point = new Point(this.posArr[4].x3,this.posArr[4].y3);
        var edgePos54:Point = new Point(this.posArr[4].x4,this.posArr[4].y4);

        this.debugDrawPointWthColor([edgePos51.x,edgePos51.y],0x008800);
        this.debugDrawPointWthColor([edgePos52.x,edgePos52.y],0xFFFFFF);
        this.debugDrawPointWthColor([edgePos53.x,edgePos53.y],0x00FF00);
        this.debugDrawPointWthColor([edgePos54.x,edgePos54.y],0xFFFFFF);
        this.debugDrawLineWithColor([edgePos51.x,edgePos51.y], [edgePos54.x,edgePos54.y],0xFFFF00);
        this.debugDrawLineWithColor([edgePos52.x,edgePos52.y], [edgePos53.x,edgePos53.y],0x00FFFF);


        var edgePos61:Point = new Point(this.posArr[5].x1,this.posArr[5].y1);
        var edgePos62:Point = new Point(this.posArr[5].x2,this.posArr[5].y2);
        var edgePos63:Point = new Point(this.posArr[5].x3,this.posArr[5].y3);
        var edgePos64:Point = new Point(this.posArr[5].x4,this.posArr[5].y4);

        this.debugDrawPointWthColor([edgePos61.x,edgePos61.y],0x000088);
        this.debugDrawPointWthColor([edgePos62.x,edgePos62.y],0xFFFFFF);
        this.debugDrawPointWthColor([edgePos63.x,edgePos63.y],0x0000FF);
        this.debugDrawPointWthColor([edgePos64.x,edgePos64.y],0xFFFFFF);
        this.debugDrawLineWithColor([edgePos61.x,edgePos61.y], [edgePos64.x,edgePos64.y],0xFFFF00);
        this.debugDrawLineWithColor([edgePos62.x,edgePos62.y], [edgePos63.x,edgePos63.y],0x00FFFF);

        this.holeEageLines[0] = new Line(new Point(edgePos11.x,edgePos11.y),new Point( edgePos14.x,edgePos14.y));
        this.holeEageLines[1] = new Line(new Point(edgePos13.x,edgePos13.y),new Point(edgePos12.x,edgePos12.y));

        this.holeEageLines[2] = new Line(new Point(edgePos24.x,edgePos24.y), new Point(edgePos21.x,edgePos21.y));
        this.holeEageLines[3] = new Line(new Point(edgePos22.x,edgePos22.y), new Point(edgePos23.x,edgePos23.y));
        
        this.holeEageLines[4] = new Line(new Point(edgePos33.x,edgePos33.y), new Point(edgePos31.x,edgePos31.y));
        this.holeEageLines[5] = new Line(new Point(edgePos32.x,edgePos32.y), new Point(edgePos34.x,edgePos34.y));
        
        this.holeEageLines[6] = new Line(new Point(edgePos41.x,edgePos41.y), new Point(edgePos43.x,edgePos43.y));
        this.holeEageLines[7] = new Line(new Point(edgePos44.x,edgePos44.y), new Point(edgePos42.x,edgePos42.y));

        this.holeEageLines[8] = new Line(new Point(edgePos51.x,edgePos51.y), new Point(edgePos54.x,edgePos54.y));
        this.holeEageLines[9] = new Line(new Point(edgePos53.x,edgePos53.y), new Point(edgePos52.x,edgePos52.y));
        this.holeEageLines[10] = new Line(new Point(edgePos64.x,edgePos64.y ), new Point(edgePos61.x,edgePos61.y));
        this.holeEageLines[11] = new Line(new Point(edgePos62.x,edgePos62.y), new Point(edgePos63.x,edgePos63.y));
 
        this.debugDrawLineWithColor([edgePos34.x,edgePos34.y], [edgePos64.x,edgePos64.y],0x000088);  // //上
        this.debugDrawLineWithColor([edgePos43.x,edgePos43.y], [edgePos13.x,edgePos13.y],0x0000FF);  //  //下
        this.debugDrawLineWithColor([edgePos14.x,edgePos14.y], [edgePos24.x,edgePos24.y],0xFF0000);  // //左下
        this.debugDrawLineWithColor([edgePos23.x,edgePos23.y], [edgePos33.x,edgePos33.y],0x00FF00);  //  //左上
   
        this.debugDrawLineWithColor([edgePos54.x,edgePos54.y], [edgePos44.x,edgePos44.y],0x880000);  //  //右下
        this.debugDrawLineWithColor([edgePos63.x,edgePos63.y], [edgePos53.x,edgePos53.y],0x008800);  // //右上

        this.tableEageLines[0] = new Line(new Point(edgePos34.x,edgePos34.y), new Point(edgePos64.x,edgePos64.y));//上
        this.tableEageLines[1] = new Line(new Point(edgePos43.x,edgePos43.y), new Point(edgePos13.x,edgePos13.y));//下
        this.tableEageLines[2] = new Line(new Point(edgePos14.x,edgePos14.y), new Point(edgePos24.x,edgePos24.y));//左下
        this.tableEageLines[3] = new Line(new Point(edgePos23.x,edgePos23.y), new Point(edgePos33.x,edgePos33.y)); //左上
        this.tableEageLines[4] = new Line(new Point(edgePos54.x,edgePos54.y), new Point(edgePos44.x,edgePos44.y));//右下
        this.tableEageLines[5] = new Line(new Point(edgePos63.x,edgePos63.y), new Point(edgePos53.x,edgePos53.y));//右上
    }
    private TrapezoidBallSide(long: number, middle: number, h: number) {   //左边边临界值
        var lift_x = this.posArr[2].x1;
        //右边边临界值
        var right_x = this.posArr[5].x2;
        //左边x值
        this.posArr[2].x3 = lift_x + h;
        this.posArr[1].x3 = lift_x + h;
        this.posArr[1].x4 = lift_x + h;
        this.posArr[0].x4 = lift_x + h;
        //右边x值
        this.posArr[5].x3 = right_x - h;
        this.posArr[4].x3 = right_x - h;
        this.posArr[4].x4 = right_x - h;
        this.posArr[3].x4 = right_x - h;
        //上边边临界值
        var up_y = this.posArr[2].y2;
        //下边边临界值
        var down_y = this.posArr[0].y2;
        //上边y值
        this.posArr[2].y4 = up_y + h;
        this.posArr[5].y4 = up_y + h;
        //下边y值
        this.posArr[0].y3 = down_y - h;
        this.posArr[3].y3 = down_y - h;
        //左边y值
        this.posArr[2].y3 = this.posArr[2].y1 + long;
        this.posArr[1].y3 = this.posArr[1].y2 - middle;
        this.posArr[1].y4 = this.posArr[1].y1 + middle;
        this.posArr[0].y4 = this.posArr[0].y1 - long
        //右边y值
        this.posArr[5].y3 = this.posArr[5].y2 + long;
        this.posArr[4].y3 = this.posArr[4].y2 - middle;
        this.posArr[4].y4 = this.posArr[4].y1 + middle;
        this.posArr[3].y4 = this.posArr[3].y2 - long;
        //上边x值
        this.posArr[2].x4 = this.posArr[2].x2 + long;
        this.posArr[5].x4 = this.posArr[5].x1 - long;
        //下边x值
        this.posArr[0].x3 = this.posArr[0].x2 + long;
        this.posArr[3].x3 = this.posArr[3].x1 - long;
    }
    /**错误消息弹出 */
    public errorMsgPopup(msg: string) {
        this.addChild(this.errorMsgMain);
        this.errorMsgMain.errorMsgShow(msg);
    }

    public reflect(out:Point, invec:Point, normal:Point) 
    {
        var dot = invec.x* normal.x+ invec.y * normal.y;
        out.x = invec.x - 2 * normal.x * dot;
        out.y = invec.y- 2 * normal.y * dot;
    }


    public CheckLeftDraw(px:number,py:number,pos:Point,veloctity:Point ):boolean
    {
         let isImpactWithWall :boolean = false;
         let isImpactWithHole :boolean = false;
                pos.x = px;
                pos.y = py;
        // 撞到了左边的墙或者洞
        if (px < this.posArr[0].x1 + this._r) { 
            //碰到了左边的墙 
            if ((py < this.posArr[0].y1 && py > this.posArr[1].y1) //下边界
            ||(py < this.posArr[1].y2 && py> this.posArr[2].y1)) //上边界
            {
                pos.x = this.posArr[0].x1 + this._r;
                veloctity.x *= this.bounce;  
                isImpactWithWall = true;
                console.log("碰到了左边的墙 球的位置 " + pos.x + "," + pos.y + "速度" + veloctity.x + ","+ veloctity.y);
            }
            else if (py >= this.posArr[0].y1) {//球碰撞进0号洞
                var dx: number = px - this.posArr[0].x1;   
                var dy: number = py - this.posArr[0].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);//球和洞的距离
                if (dist < this._r) {
                    this.reboundDraw(pos,veloctity, this.posArr[0].x1, this.posArr[0].y1, this.bounce);
                    console.log("碰到了左边的墙洞0 " + pos.x + "," + pos.y + "速度" + veloctity.x + ","+ veloctity.y);
                    isImpactWithHole = true;
                }
            }
            else if (py <= this.posArr[1].y1 && py > this.posArr[1].hy) {//球碰撞进1号洞左边
                var dx: number = px - this.posArr[1].x1;
                var dy: number = py - this.posArr[1].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.reboundDraw(pos,veloctity, this.posArr[1].x1, this.posArr[1].y1, this.bounce);
                     console.log("碰到了左边的墙洞1左边 " + pos.x + "," + pos.y + "速度" + veloctity.x + ","+ veloctity.y);
                    isImpactWithHole = true;
                }
            }
            else if (py >= this.posArr[1].y2 && py < this.posArr[1].hy) {//球碰撞进1号洞右边

                var dx: number = px - this.posArr[1].x2;
                var dy: number = py - this.posArr[1].y2;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.reboundDraw(pos,veloctity, this.posArr[1].x2, this.posArr[1].y2, this.bounce);
                    console.log("碰到了左边的墙洞1右边 " + pos.x + "," + pos.y + "速度" + veloctity.x + ","+ veloctity.y);
                    isImpactWithHole = true;
                }
            }
            else if (py >= this.posArr[2].y1) {//球碰撞进2号洞
                var dx: number = px - this.posArr[2].x1;
                var dy: number = py - this.posArr[2].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
          
                    this.reboundDraw(pos,veloctity, this.posArr[2].x1, this.posArr[2].y1, this.bounce);
                    console.log("碰到了左边的墙洞0 " + pos.x + "," + pos.y + "速度" + veloctity.x + ","+ veloctity.y);
                    isImpactWithHole = true;
                }
            }
        }
        if( isImpactWithHole || isImpactWithWall){
            return true;
        }
        return false;
    }
    
    public CheckTopDraw(px:number,py:number,pos:Point,veloctity:Point ):boolean
    {
        let isImpactWithWall :boolean = false;
        let isImpactWithHole :boolean = false;
        pos.x = px;
        pos.y = py;
        if (py < this.posArr[2].y2 + this._r) {
            if (px> this.posArr[2].x1 && px< this.posArr[5].x1) {
                pos.y = this.posArr[2].y2 + this._r;
                veloctity.y *= this.bounce;
                console.log("碰到了上边的墙 球的位置 " + pos.x + "," + pos.y + "速度" + veloctity.x + ","+ veloctity.y);
                isImpactWithWall = true;
            }
            if (py <= this.posArr[2].y2) {
                var dx: number = px- this.posArr[2].x2;
                var dy: number = py - this.posArr[2].y2;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.reboundDraw(pos,veloctity, this.posArr[2].x2, this.posArr[2].y2,  this.bounce);
                    isImpactWithHole = true;
                    console.log("碰到了上边的墙洞2 球的位置 " + pos.x + "," + pos.y + "速度" + veloctity.x + ","+ veloctity.y);
                }
            }
            if (py >= this.posArr[5].y1) {
                var dx: number = px- this.posArr[5].x1;
                var dy: number = py - this.posArr[5].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.reboundDraw(pos,veloctity, this.posArr[5].x1, this.posArr[5].y1,  this.bounce);
                    isImpactWithHole = true;
                    console.log("碰到了上边的墙洞5 球的位置 " + pos.x + "," + pos.y + "速度" + veloctity.x + ","+ veloctity.y);
                }
            }
        }
        if( isImpactWithHole || isImpactWithWall){
            return true;
        }

        return false;
    }

    public CheckBottomDraw(px:number,py:number,pos:Point,veloctity:Point ):boolean
    {
        let isImpactWithWall :boolean = false;
        let isImpactWithHole :boolean = false;
        pos.x = px;
        pos.y = py;
        if (py > this.posArr[0].y2 - this._r) {
            if (px> this.posArr[0].x2 && px< this.posArr[3].x1) {
                pos.y = this.posArr[0].y2 - this._r;
                veloctity.y *= this.bounce;
                isImpactWithWall = true;
                console.log("碰到了下边的墙 球的位置 " + pos.x + "," + pos.y + "速度" + veloctity.x + ","+ veloctity.y);
            }
            if (py <= this.posArr[0].y2) {
                var dx: number = px- this.posArr[0].x2;
                var dy: number = py - this.posArr[0].y2;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.reboundDraw(pos,veloctity, this.posArr[0].x2, this.posArr[0].y2,  this.bounce);
                    isImpactWithHole = true;
                    console.log("碰到了下边的墙 洞0 球的位置 " + pos.x + "," + pos.y + "速度" + veloctity.x + ","+ veloctity.y);
                }
            }
            if (py >= this.posArr[3].y1) {
                var dx: number = px- this.posArr[3].x1;
                var dy: number = py - this.posArr[3].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.reboundDraw(pos,veloctity, this.posArr[3].x1, this.posArr[3].y1,  this.bounce);
                    isImpactWithHole = true;
                    console.log("碰到了下边的墙 洞3 球的位置 " + pos.x + "," + pos.y + "速度" + veloctity.x + ","+ veloctity.y);
                }
            }
        }
        if( isImpactWithHole || isImpactWithWall){
            return true;
        }
        return false;
    }

    public CheckRightDraw(px:number,py:number,pos:Point,veloctity:Point ):boolean
    {
        let isImpactWithWall :boolean = false;
        let isImpactWithHole :boolean = false;
        pos.x = px;
        pos.y = py;
        if (px > this.posArr[3].x2 - this._r) 
        {        
            if ((py < this.posArr[3].y2 && py > this.posArr[4].y1)
                ||(py < this.posArr[4].y2 &&py> this.posArr[5].y2)) {
                pos.x  = this.posArr[3].x2 - this._r;
                veloctity.x*= this.bounce;
                isImpactWithWall = true;
                    console.log("碰到了右边的墙 球的位置 " + pos.x + "," + pos.y + "速度" + veloctity.x + ","+ veloctity.y);
            }
            if (py<= this.posArr[3].y2) {
                var dx: number = px- this.posArr[3].x2;
                var dy: number =py- this.posArr[3].y2;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.reboundDraw(pos,veloctity, this.posArr[3].x2, this.posArr[3].y2,this.bounce);
                    isImpactWithHole = true;
                    console.log("碰到了右边的墙洞3 " + pos.x + "," + pos.y + "速度" + veloctity.x + ","+ veloctity.y);
                }
            
            }
            if (px <= this.posArr[4].y1 && px > this.posArr[4].hy) {
                var dx: number = px - this.posArr[4].x1;
                var dy: number =py - this.posArr[4].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) { 
                    this.reboundDraw(pos,veloctity, this.posArr[4].x1, this.posArr[4].y1, this.bounce);
                    isImpactWithHole = true;
                    console.log("碰到了右边的墙洞4 左" + pos.x + "," + pos.y + "速度" + veloctity.x + ","+ veloctity.y);
                }
            
            }
            if (px >= this.posArr[4].y2 && px < this.posArr[4].hy) {
                var dx: number = px - this.posArr[4].x2;
                var dy: number = py- this.posArr[4].y2;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.reboundDraw(pos,veloctity, this.posArr[4].x2, this.posArr[4].y2, this.bounce);
                    isImpactWithHole = true;
                    
                }
            }
            if (px >= this.posArr[5].y1) {
                var dx: number = px - this.posArr[5].x1;
                var dy: number = py - this.posArr[5].y1;
                var dist: number = Math.sqrt(dx * dx + dy * dy);
                if (dist < this._r) {
                    this.reboundDraw(pos,veloctity, this.posArr[5].x1, this.posArr[5].y1, this.bounce);
                    isImpactWithHole = true;
                    console.log("碰到了右边的墙洞5" + pos.x + "," + pos.y + "速度" + veloctity.x + ","+ veloctity.y);
                }
            }
        }
        if( isImpactWithHole || isImpactWithWall){
            return true;
        }
        return false;
    }
    
}